How to replace ereg?

I get the following message for some php that I have to use but didn't write:

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

This is line 466:

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

I tried just replacing preg_match, but it could not recognize the modifier = in the regular expression. I'm still not very good at regular expression, and solving this requires me to study the needs of regular expressions and regexp preg_match needs (which, if I'm not mistaken, are different) ... Could you guys help me with this?

thanks

+7
php regex pcre posix-ere
source share
3 answers

POSIX extended regular expressions (POSIX ERE, used by ereg ) and Perl-compatible regular expressions (PCRE, used by preg_match ) are very similar. With the exception of some special POSIX expressions , PCRE is a superset of POSIX ERE.

This means that you just need to place the POSIX ERE regular expressions in delimiters (here / ) and avoid any appearance of this character inside the regular expression, and you have a valid PCRE regular expression:

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

So:

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

Try:

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

The regular expression in preg_match must be enclosed between a pair of delimiters, which does not correspond to the deprecated ereg () function.

+2
source share

The preg_ family assumes that the regular expression will be limited. Instead:

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

to try:

 '/^([^=]*)=["\']?([^"\']*)["\']?$/' 
0
source share

All Articles