1

ereg and eregi functions will be deleted from Php. Please help to find alternatives for the following ereg functions:

1) To allow IP addresses only for specific ranges:

$targetAddr = "60.37..*..*";  
if (!ereg($targetAddr, $_SERVER['REMOTE_ADDR'])) {
die;
} 

2) To replace series of points like .......................

$message = ereg_replace("[.]{3,}", "... ", $message);
Gumbo
  • 643,351
  • 109
  • 780
  • 844
user
  • 751
  • 2
  • 10
  • 18

2 Answers2

3

Just use preg_match and preg_replace. Those regexes will work the same with Perl regex syntax.

However, the first regex should probably be written

$targetAddr = "60[.]37[.].*[.].*";

if it should do what you say it should. (Alternatively, use backslashes.)

Thomas
  • 174,939
  • 50
  • 355
  • 478
1

This works for me:

$targetAddr = "/^60\.37\..+/"; 
if (!preg_match($targetAddr, $_SERVER['REMOTE_ADDR'])) {
die;
}

$message = preg_replace("/[.]{3,}/", "... ", $message);

Thomas and Anomareh, your answers helped me to find the right solution. Thank you.

user
  • 751
  • 2
  • 10
  • 18