0

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!

Martin.
  • 10,494
  • 3
  • 42
  • 68
John White
  • 39
  • 8

4 Answers4

4

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);
Tim S.
  • 13,597
  • 7
  • 46
  • 72
1

Change these lines to

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

which uses str_replace & preg_replace, non-deprecated functions.

Martin.
  • 10,494
  • 3
  • 42
  • 68
  • What if there are 3 spaces in a row? – Marcus Nov 14 '11 at 11:53
  • Well for the first one I think he does because you only remove double space.. but what if there are three? – SERPRO Nov 14 '11 at 11:53
  • @Marcus: if there are 3 space in a row, there will be 2 of them replaced to one, it will result in 2 spaces which will result in one space – Martin. Nov 14 '11 at 11:57
  • 1
    @Martin that's not true since the replace doesn't start over from the beginning: http://codepad.org/4jD3ONN8 – Marcus Nov 14 '11 at 12:01
0

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.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

This code will work for that:

$response = preg_replace("#[\r\n]#", "", $response);
$response = preg_replace("#\s+#m", "$1", $response);
SERPRO
  • 10,015
  • 8
  • 46
  • 63