A function which will escape a given string and make it "safe" if I may say so.
It's good to always escape a string especially when you're using them into your SQL statements.
The function:
<?php
function escape_string($str) {
if ($str !== null) {
$str = str_replace(array('\\','\''),array('\\\\','\\\''),$str);
$str = "'".$str."'";
} else {
$str = "null";
}
return $str;
}
?>
Usage:
<?php
echo escape_string("asdasdlkajsdas dasldkjasd'a sdasd'as ''asd''as'd' as'd'asdasdkajsd");
?>
...this will output something like this:
'asdasdlkajsdas dasldkjasd\'a sdasd\'as \'\'asd\'\'as\'d\' as\'d\'asdasdkajsd'