Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前正在使用以下内容从符号/未知字符中清除字符串:
$title = preg_replace("/[^a-zA-Z0-9-]/", " ", $title);
但是,我不想从字符串中删除 '&'
有人可以帮我吗?
谢谢!
看看这个漂亮的备忘单,它会在以后派上用场。
字符类的^开头:[^... ]表示该类中的所有字符都应从匹配中排除。在您的情况下,不应删除此字符。所以像这样添加&到类中:
^
[^... ]
&
$title = preg_replace("/[^a-zA-Z0-9-&;]/", " ", $title);