如何从PHP中的字符串中删除Unicode字符(LEFT_TO_RIGHT_MARK) [英] How to strip unicode chars (LEFT_TO_RIGHT_MARK) from a string in php
本文介绍了如何从PHP中的字符串中删除Unicode字符(LEFT_TO_RIGHT_MARK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从字符串中删除LEFT-TO-RIGHT-MARK(\ u200e)和RIGHT-TO-LEFT-MARK(\ u200f),然后再将其编码为JSON.以下两种似乎都不起作用:
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);
感谢您的帮助!
推荐答案
在解决了这一问题几天后,我终于找到了答案!
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);
这篇关于如何从PHP中的字符串中删除Unicode字符(LEFT_TO_RIGHT_MARK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文