php special charecters

How to add/allow special characters in mysql – php data interchange

To prepare data for insertion to a text field in MySQL via PHP use the
following function;

$raw_additional_notes=$_POST['additional_notes'];
$additional_notes = mysql_escape_string($raw_additional_notes);    ///to escape the special charecters		
and to get it back to normal after reading it from the database...
$raw_additional_notes= stripslashes($additional_notes);

Basically the special characters are allowed in mysql with backslaches (“\”) therefore to add any such charectar, string needs to rewritten according to mysql. Using mysql_escape_string() function  the slashes can be added in string.

stripslashes() can revert back the same string deleting slashes.


 

 

Advertisements