Special characters from PHP to JavaScript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
platforge
Forum Newbie
Posts: 2
Joined: Mon Nov 21, 2011 3:59 pm

Special characters from PHP to JavaScript

Post by platforge »

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.

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
);
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
Last edited by Benjamin on Mon Nov 21, 2011 4:44 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Special characters from PHP to JavaScript

Post by maxx99 »

Do you still want those special chars passed as a parameter to your object? Or do you just need to filter them out? Leave text only?
Post Reply