December 02th, 2008
How to strip Unicode and UTF using PHP
Topics: Code, Php, HowtoI have been working on a PHP cotract recently and I needed to strip out anything non-asci.
Here’s a little function I wrote that takes a string and returns it minus all the crazy symbols:
// Function to strip out all non asci characters
function strip_utf($string) {
for ($i = 0; $i < strlen ($string); $i++)
if (ord($string[$i]) > 127)
$string[$i] = " ";
return $string;
}
Hope it helps, Dave.