I have a problem that needs to be solved. I can't use preg_replace or str_replace
because we can't predetermine the characters since the data comes from form input.
I am trying to remove these characters from this $name "Test ½ ´ ¤ £ € ¨"
##½ ´ ¤ £ € ¨;
I tried the following methods but none of them worked
$name = "Test ½ ´ ¤ £ € ¨"; mb_convert_encoding(strval($name); utf8_decode(strval($name);My ideal output is
Test
You can always iterate over the characters in a string. But be careful: PHP does not support Unicode natively.
This iterates over the multibyte characters in the user-supplied string and allows you to perform any operation on them. The example builds a resulting string, omitting the characters you mentioned. (Not debugged, sorry.)
(IMHO, I think your reasons for avoiding string replacement functions are probably wrong. The benefit of using regex character classes is this: regex authors have solved a lot of weird edge cases where Unicode contains many disturbing situations.)