tags:

views:

183

answers:

2

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);
+3  A: 

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
A: 

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.

Guanche
If Thomas helped you find the solution, you should have accepted his answer IMHO.
robertbasic