[英]How to add all of these symbols (“ ” ! ? ; " , . / ” “ ' ) in preg_replace pattern in php?
I have: 我有:
$input = str_replace('/all these symbols/', "", $input);
Can't really understand the pattern syntax for preg_match
and preg_replace
. 不能真正理解preg_match
和preg_replace
的模式语法。 Sometimes people use '+ - * ^ $ \\s'
and different kind of brackets there. 有时人们在这里使用'+ - * ^ $ \\s'
和其他类型的括号。 Tried to read the manual, but don't really get it. 试图阅读该手册,但并没有真正理解它。 Can i find somewhere more clear information about all the possibilities of the preg syntax? 我可以在某处找到有关preg语法所有可能性的更清晰信息吗? Thanks in advance. 提前致谢。
Just put those characters into character class as shown in below example: 只需将这些字符放入字符类中,如下面的示例所示:
$replaced = preg_replace("/[“”!?;\",.\/”“']/u", " ", "hello!?; “how are you”");
print_r($replaced);
The output: 输出:
hello how are you
您可以使用方括号,只需要转义正确的字符即可:
echo preg_replace('/[“”!?;",.\/”“\']/', '', 'a!b?c');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.