How to replace ereg?

我的未来我决定 提交于 2019-11-28 12:08:46

POSIX extended regular expressions (POSIX ERE, used by ereg) and Perl-combatible regular expressions (PCRE, used by preg_match) are very similar. Except from some special POSIX expressions, PCRE is a superset of POSIX ERE.

That means you just need to put your POSIX ERE regular expressions into delimiters (here /) and escape any occurrence of that character inside the regular expression and you have a valid PCRE regular expression:

/^([^=]*)=["']?([^"']*)["']?$/

So:

preg_match('/^([^=]*)=["\']?([^"\']*)["\']?$/', $v, $a3)

Try:

if(preg_match('~^([^=]*)=["\']?([^"\']*)["\']?$~',$v,$a3))

The regex in preg_match needs to be enclosed between a pair of delimiters, which is not the case with the deprecated ereg() function.

the preg_ family expects the regex to be delimited. Instead of:

'^([^=]*)=["\']?([^"\']*)["\']?$'

try:

'/^([^=]*)=["\']?([^"\']*)["\']?$/'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!