OK So what's the main difference between the two?


function validateIP($ip) 
{ 
    $valid = false; 

$regexp = '/^((1?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(1?\d{1,2}|2[0-4]\d|25[0-5])$/'; 

if (preg_match($regexp, $ip)) 
{ 
    $valid = true; 
} 

return $valid; 
} 

When I replace preg_match with ereg it no longer works, so what is the difference, when they both do a regular expression match?

    OK So what's the main difference between the two?

    1. preg_match() may be faster than ereg(), according to the PHP Manual.
    2. The PCRE functions are binary safe, but the ereg functions are not.
    3. The ereg functions are becoming second class citizens compared to PCRE.

    When I replace preg_match with ereg it no longer works, so what is the difference, when they both do a regular expression match?

    PCRE patterns have delimiters, but the ereg patterns do not.

      Also, "\d" isn't recognised by ereg().

        Also, ereg regexes do not use delimiters (the starting and ending slashes in this case), which includes another difference: there are a number of modifiers which can be applied to preg expressions following the closing delimiter.

          Write a Reply...