Special characters from PHP to JavaScript

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

Locked
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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Special characters from PHP to JavaScript

Post by Benjamin »

:arrow: Duplicate = Locked
Locked