Trouble printing description in text box field...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Curtis782
Forum Commoner
Posts: 31
Joined: Tue Oct 25, 2005 3:34 pm

Post by Curtis782 »

I was looking at the code and thought it might have something to do with this?

Code: Select all

echo "<script type=\"text/javascript\">
var Descriptions = new Array();\n";
foreach ($description as $key => $value)
{
    echo "Descriptions[\'$key\'] = \'$value\'\n";
}
echo '</script>';
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

yeah! you are right! error lies there. the thing is you have descriptions which contains ' and the foreach loop is using ' to contain the value which messes up the array output. So you have to change line 5 to

Code: Select all

echo "Descriptions[\"$key\"] = \"$value\"\n";
though i sometimes use this :arrow:

Code: Select all

echo "Descriptions[\"".addslashes($key)."\"] = \"".addslashes($value)."\"\n";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

var_export() works so much better at that ;)
Post Reply