Special characters from PHP to JavaScript
Posted: Mon Nov 21, 2011 4:11 pm
Hi,
We are trying to develop a application which reads the tweets from a user's twitter stream and then passes it to a Javascript for client side processing.
Example code is as below.
The table contains tweets which are previous stored. We are trying to read it here and construct a Clue object.
But despite our best efforts one or the other special character appears in the tweet and breaks the construction. This leads to the Puzzle object not being constructed properly.
Any suggestions of what we could do so that irrespective of the type of character in the tweet the Puzzle object is constructed properly.
If you need further information, please let me know.
Thanks,
Raghu
We are trying to develop a application which reads the tweets from a user's twitter stream and then passes it to a Javascript for client side processing.
Example code is as below.
Code: Select all
var sample = new Puzzle (
"5748185539682739085",
[
<?php require 'config.php';
$select = mysql_query("SELECT * FROM ".$username."_game");
while($select_game = mysql_fetch_array($select))
{
$question = $select_game['Tweet'];
$text3 = $question;
$text2 = preg_replace('/[^a-zA-Z0-9\\\@\!\#\$\%\^\&\*\:\?\;\.\,\(\)\[\]\{\}\/\`\~|\s\r\n]/', '', $text3);
$text1 = str_replace("\n","",$text2);
$text = preg_quote($text1);
echo 'new Clue('.$select_game['sample'].', "'.$text.'", "'.$select_game['Word'].'", "", '.$select_game['AXIS'].', '.$select_game['X'].', '.$select_game['Y'].') ,
';
}?>
],
21,
21
);But despite our best efforts one or the other special character appears in the tweet and breaks the construction. This leads to the Puzzle object not being constructed properly.
Any suggestions of what we could do so that irrespective of the type of character in the tweet the Puzzle object is constructed properly.
If you need further information, please let me know.
Thanks,
Raghu