Return to Snippet

Revision: 38145
at December 27, 2010 02:24 by daipratt

Initial Code
//Remove from a single line string
$output = "Likening ‘not-critical’ with";
$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
echo $output;

//Remove from a multi-line string
$output = "Likening ‘not-critical’ with \n Likening ‘not-critical’ with \r Likening ‘not-critical’ with. ' ! -.";
$output = preg_replace('/[^(\x20-\x7F)\x0A\x0D]*/','', $output);
echo $output;

Initial URL

Initial Description
This will remove all non-ascii characters / special characters from a string.

Initial Title
PHP regex - Remove special characters from a string

Initial Tags

Initial Language