The following regular rules:
$a='2 垌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); |