Home  >  Article  >  Backend Development  >  PHP正则的Unknown Modifier错误解决方法_php技巧

PHP正则的Unknown Modifier错误解决方法_php技巧

WBOY
WBOYOriginal
2016-05-17 09:27:41912browse

如下正则:

$a='2tóngdòng
3';
echo preg_replace('/[^/','',$a);

会提示:

Warning: preg_replace(): Unknown modifier 'p' in E:\phpLearn\test.php on line 12

原因是:

在正则模式中,用/做定界符,但正则中也含有/,因此会出现此错误,PHP误当后面的一个中的斜杠是结束的定界符。

解决办法:

1、加一个转义符:

echo preg_replace('/[^/','',$a);

2、改其它定界符:如

echo preg_replace('{[^}','',$a);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn