Function eregi_replace() is deprecated

1.8k Views Asked by At

I am getting this error message appear when trying to support to a payment gateway:

Message: Function eregi_replace() is deprecated
Message: Function eregi_replace() is deprecated

This is the code its relating to in the payment gateway

        $response = eregi_replace ( "[[:space:]]+", " ", $response );
        $response = eregi_replace ( "[\n\r]", "", $response );

Any help in solving this error would be great!

4

There are 4 best solutions below

4
On BEST ANSWER

When a function is deprecated, it means it's not supported anymore and the use of it is discouraged. In fact, all eregi functions are deprecated.

You should try another function, such as preg_replace(). This could mean you have to edit your regular expression.

This should work

$response = preg_replace ("/\s+/", " ", $response);
$response = preg_replace ("/[\r\n]/", "", $response);
4
On

Change these lines to

 $response = preg_replace ( "~[ ]+~", " ", $response );
 $response = str_replace ( array("\n", "\r"), "", $response );

which uses str_replace & preg_replace, non-deprecated functions.

0
On

Change these lines to

$response = preg_replace ( "/[[:space:]]+/", " ", $response );
$response = preg_replace ( "/[\n\r]/", "", $response );

which uses PCRE, the preferred engine and the reason EREG is deprecated.

0
On

This code will work for that:

$response = preg_replace("#[\r\n]#", "", $response);
$response = preg_replace("#\s+#m", "$1", $response);