I am trying to remove special characters from a string.
The user enters text into a WYSWIG editor and clicks save, then the data is saved in the DB.
However is the '
is entered (Eg in the word don't
the script fails.
I have tried the below but it isnt working, can anyone advise?
$content=$_POST[content];
function clean($content) {
$string = str_replace(' ', '-', $content); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $content); // Removes special chars.
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
$result=mysql_query("update TABLE set content='$string' WHERE id='$id'");