Domanda

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!

È stato utile?

Soluzione

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);

Altri suggerimenti

Change these lines to

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

which uses str_replace & preg_replace, non-deprecated functions.

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.

This code will work for that:

$response = preg_replace("#[\r\n]#", "", $response);
$response = preg_replace("#\s+#m", "$1", $response);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top