Solution to PHP regular Unknown Modifier error_PHP tutorial

WBOY
Release: 2016-07-21 15:40:09
Original
1134 people have browsed it

The following regular rules:

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

will prompt:

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

The reason is:

In the regular pattern, / is used as the delimiter, but the regular pattern also contains /, so this error will occur. PHP mistakenly thinks that the slash in the following is the end delimiter.

Solution:

1. Add an escape character:

echo preg_replace('/[^<]*?/','',$a);

2. Change other delimiters: such as

echo preg_replace('{[^<]*?}','',$a);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321409.htmlTechArticleThe following regular rules: $a='2spannobrtóngspan class="h"dòng/span/nobrbr垌/span3'; echo preg_replace('/span class="h"[^]*?/span/','',$a); will prompt: Warning: preg_replace(): Unknown mo...
Related labels:
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