I'm trying to remove LEFT-TO-RIGHT-MARK (\u200e) and RIGHT-TO-LEFT-MARK (\u200f) from a string before encoding it as JSON. Neither of the following seems to work:
$s = mb_ereg_replace("\u200e", '', $s);
$s = preg_replace("#\u200e#u", '', $s);
$s = preg_replace("#\u200e#", '', $s);
Any help is appreciated!
After wrestling with this issue for a couple of days, I finally have found the answer!
$str = preg_replace('/(\x{200e}|\x{200f})/u', '', $str);
Your Unicode escaping is wrong, this should work:
preg_replace('/\x20(\x0e|\x0f)/', '', $string)
Test:
<?php
$string = chr(0x20) . chr(0x0e) . 'fo' . chr(0x20) . chr(0x0e) . 'o' . chr(0x20) . chr(0x0f);
echo $string . "\n";
echo preg_replace('/\x20(\x0e|\x0f)/', '', $string);
?>
Or, use str_replace()
:
str_replace(array("\x20\x0e", "\x20\x0f"), '', $string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With