Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

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

 Share


HACK1949

Recommended Posts

https://www.jb51.net/article/22304.htm

 

如下正则:

$a='2<span><nobr>tóng<span class="h">dòng</span></nobr><br>垌</span>3';
echo preg_replace('/<span class="h">[^<]*?</span>/','',$a);

会提示:

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

原因是:

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

解决办法:

1、加一个转义符:

echo preg_replace('/<span class="h">[^<]*?<\/span>/','',$a);

2、改其它定界符:如

echo preg_replace('{<span class="h">[^<]*?</span>}','',$a);
Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...