Mega Code Archive

 
Categories / Php / MySQL Database
 

Fix to PHP4-MySQL problem

<?php function mysql_unescape_string($s) { $sl=strlen($s); for ($a=0;$a<$sl;$a++) { $c=substr($s,$a,1); if ($c=="\\") { switch(substr($s,$a+1,1)) { case "0": $c="\0"; break; case "n": $c="\n"; break; case "t": $c="\t"; break; case "r": $c="\r"; break; case "b": $c="\b"; break; case "\'": $c="'"; break; case "\"": $c="\""; break; case "\\": $c="\\"; break; case "%": $c="\%"; break; case "_": $c="_"; break; default: echo("unhandled exception!"); } // advance the counter because we are pealing off the char after the scanned \ $a++; } $s2.=$c; } return $s2; } ?> Example : ======== In PHP3, the code: ... $row=mysql_fetch_row($res); $fielddata=strval($row[0]); .... becomes (in PHP4): .... $row=mysql_fetch_row($res); $fielddata=mysql_unescape_string(strval($row[0]));