"ASCII" format characters... that's all of 'em.
No -- Unicode contains many, many more characters than ASCII.
$string = ereg_replace('[!#$%&\'()*+,-./ :;?@\`{|}~^"]','',$string);
This is very slow and quite incomprehensive. Instead, split the string and use array_filter(). ctype_alnum() would be preferable, but it doesn't always exist so we may have to create it:
Code:
if(!function_exists('ctype_alnum')) {
$alphabet = array_map('chr', array_merge(range(0x61, 0x7a), range(0x41, 0x5a));
function ctype_alnum($tr) {
return is_numeric($tr) || in_array($tr, $alphabet);
}
}
function only_alphanumeric($tr) {
return implode('', array_filter(str_split($tr), 'ctype_alnum'))
}
$string = only_alphanumeric($tr);
Bookmarks