I'm trying to strip hidden control chars (especially \x{89} and \x{88}) with preg_replace() from a string. It is "ˆText" (it starts with an "\x{88}" char), mb_detect_encoding says it is UTF-8.
The code used is $result = preg_replace('/\x{88}/u','',$string); but the result is null.
If I use the code without /u modifier I get "�Text", the control char is replaced with a replacement char (U+FFFD).
I'm using PHP 7.1 on Windows. The same search with BBEdit and NotePad++ replaces the chars correctly.
Any ideas?
Thanks, A.
preg_replacereturns null then it is due to an error. Try callingpreg_last_errorafter yourpreg_replace. Then compare the error code with the errors mentioned in the doc [here] (php.net/manual/en/function.preg-last-error.php)ˆis not\x{88}, it is\x{2C6}. Also, why not just usestr_replace("\u{02C6}", "", $string)?preg_last_errorreturs code "4" that is PREG_BAD_UTF8_ERROR. Thanks.