zidian
08-08-2007, 06:09 AM
I would just like to put this code out there since no such mysql function exists to unescape a escaped string. If you have any improvements, let me know.
function mysql_real_unescape_string($input,$checkbr) {
$output = $input;
$output = str_replace("\\\\", "\\", $output);
$output = str_replace("\'", "'", $output);
$output = str_replace('\"', '"', $output);
if ($checkbr==1) {
$output = str_replace('\n\r', '\n', $output);
$output = str_replace('\r\n', '\n', $output);
$output = str_replace('\r', '\n', $output);
$output = str_replace('\n', ' ', $output);
} else if ($checkbr==2) {
$output = str_replace('\n\r', '\n', $output);
$output = str_replace('\r\n', '\n', $output);
$output = str_replace('\r', '\n', $output);
$output = str_replace("\n", "
", $output);
}
return $output;
}
?>
Just wanted to save people time trying to find an official mysql function to do it for them. To use, write 'mysql_real_unescape_string(*source*)'. :)
function mysql_real_unescape_string($input,$checkbr) {
$output = $input;
$output = str_replace("\\\\", "\\", $output);
$output = str_replace("\'", "'", $output);
$output = str_replace('\"', '"', $output);
if ($checkbr==1) {
$output = str_replace('\n\r', '\n', $output);
$output = str_replace('\r\n', '\n', $output);
$output = str_replace('\r', '\n', $output);
$output = str_replace('\n', ' ', $output);
} else if ($checkbr==2) {
$output = str_replace('\n\r', '\n', $output);
$output = str_replace('\r\n', '\n', $output);
$output = str_replace('\r', '\n', $output);
$output = str_replace("\n", "
", $output);
}
return $output;
}
?>
Just wanted to save people time trying to find an official mysql function to do it for them. To use, write 'mysql_real_unescape_string(*source*)'. :)