Why is `ereg` deprecated in PHP?

Why is it eregdeprecated in PHP?

I had many functions that used this, now they always give a warning.

What is the alternative to this?

+3
source share
4 answers

http://pl.php.net/manual/en/function.ereg.php

Note. Starting with PHP 5.3.0, the regex extension has been deprecated in favor of the PCRE extension. Calling this function generates an E_DEPRECATED notification. See the list of differences in PCRE conversion help.

+2
source

Ereg is deprecated because it has been replaced by the PCRE extension. The reason (s) has been replaced and deprecated by responding to the link below, but to save you some time, here is a copy and an inserted answer:

. preg_match(), , Perl, ereg().

PHP ereg vs. preg

, ereg , preg . , , : http://www.php.net/manual/en/reference.pcre.pattern.posix.php

, PHP 6.0 ereg, , , PHP 6.0, ereg .

+2

, :

.. PHP 5.3.0, PCRE, E_DEPRECATED. . PCRE.

+1

- , .

() :

, (PHP 5.3):

<?php
$arg=$_GET['key'];
if (ereg('^[A-Za-z0-9]+$', $arg) === FALSE){
    die('Invalid key');
}
# Do some other things with $arg
?>

, URL-:

foo.php?key=A%00text
                ^~~~

when a part texthas anything arbitrarily , which leaves a big security flaw in the code. preg_match()however, does not have this problem. Therefore, you better port your entire code to preg, as it is eregno longer available at all in PHP 6.0.

0
source

Source: https://habr.com/ru/post/1750896/


All Articles