如何更换ereg? [英] How to replace ereg?

查看:85
本文介绍了如何更换ereg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一些我必须使用但未编写的php的以下消息:

I'm getting the following message for some php I have to use but did not write:

Deprecated: Function ereg() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/html2fpdf.php on line 466

这是第466行:

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

我尝试简单地用preg_match替换,但是它无法识别正则表达式中的=修饰符..我对正则表达式还不太满意,要解决此问题,我需要学习regexp ereg需求和regexp preg_match需求(如果我没记错的话,需求会有所不同)...你们能帮我解决这个问题吗?

I tried simply replacing with preg_match, but it couldn't recognize the = modifier in the regular expression.. I'm not too good with regular expression yet and solving this requires that I learn the regexp ereg needs AND the regexp preg_match needs (which, if I am not mistaken, is different)... Could you guys help me out with this one?

谢谢

推荐答案

POSIX扩展正则表达式(POSIX ERE,由ereg使用)和与Perl兼容的正则表达式(preg_match使用的PCRE)非常相似.除了一些特殊的POSIX表达式之外,PCRE是POSIX ERE的超集.

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.

这意味着您只需要将POSIX ERE正则表达式放入定界符(此处为/),并在正则表达式中转义该字符的任何出现,并且您具有有效的PCRE正则表达式:

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:

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

所以:

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

这篇关于如何更换ereg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆