I am trying to find a way to take a string (mostly pulled from a database in a while loop), and place it in a value inside javascript.
Ex:
<?PHP
echo "<SCRIPT LANGUAGE=Javascript>";
while($row = $db->getarow($query)) {
$contents .= "'$row[0]',";
}
echo "var fb_Titles = new Array($contents,'bleah'); ";
echo "</SCRIPT>";
?>
Now, inside the database, the cell could contain titles with spaces, or slashes, or even ascii characters like tiny TM or circle R etc... pretty much ANYTHING.
The question I have, is how do I escape all that so javascript doesn't freak out on the client browser when it gets invalid chars in there?
There is "addslashes();" or "urlencode();" functions ... but I am not finding "javascriptencode();" (or something of the like).
Anyone got any bright ideas? besides making the largest find and replace function the world has ever seen for every character known?
(I posted this a while back, but no one responded... so I will try one last time)