关于PHP正则的Unknown Modifier错误_PHP

WBOY
Release: 2016-06-01 12:20:41
Original
777 people have browsed it

如下正则:

 

$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);

 

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template