可能重复:
How to use ^/$ if it's already used as a delimiter for regex in PHP?
如果我在preg_replace上加上“#”,则会出错。如何在preg_replace中包含“#”?
$document = preg_replace('#[^A-Za-z 0-9,.?$@!&;]#i', '', $document);
答案 0 :(得分:2)
使用不同的分隔符。
/[^A-Za-z 0-9,.?$@!&;#]/
答案 1 :(得分:2)
你逃避它
$document = preg_replace('#[^A-Za-z 0-9,.?$@!&;\#]#i', '', $document);
答案 2 :(得分:1)
像\#
一样逃避它。另请查看this