这是我在php中的代码
<?php
$output = "Clean this copy of invalid non ASCII ¥ äócharacters.";
$output = preg_replace('/[^(\x20-\x7F\p{Sc})]/','',$output);
echo($output);
?>
在这里,我希望保留任何货币符号,并且需要删除垃圾字符。
我应该在正则表达式中针对此问题做出哪些更改?
提前致谢
答案 0 :(得分:1)
您需要将u
修饰符添加到RegEx中,它可以很好地运行:
$output = 'Clean this copy of invalid non ASCII ¥$€ äócharacters';
$output = preg_replace('/[^(\x20-\x7F\p{Sc})]/u','',$output);
输出
Clean this copy of invalid non ASCII ¥$€ characters.
答案 1 :(得分:0)
第一个问题,你想要实现什么目标?你可以自己制作正则表达式。
像:
总结这可以是:A-Za-z0-9 然而,正则表达式有很多方法可以实现,我不知道你的情况或你想要实现的目标,但是,我希望你能用这篇文章做点什么:)
答案 2 :(得分:0)
试试这个
$output = preg_replace('/[^(A-Za-z\s\$¥€)]/u','',$output);
除了A-Z,a-z,空格和符号$,¥,€
之外,它将除去