Page 1 of 1

preg_match works, eregi doesn't

Posted: Tue Jun 25, 2002 10:28 pm
by calebsg
The following code works great:

Code: Select all

if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) {
    print "A match was found.";
} else {
    print "A match was not found.";
}
and the following doesn't work at all:

Code: Select all

if (eregi ("/php/i", "PHP is the web scripting language of choice.")) {
    print "A match was found.";
} else {
    print "A match was not found.";
}
Why would that be?

Posted: Tue Jun 25, 2002 11:22 pm
by will
the second one should be....

Code: Select all

if (eregi ("php", "PHP is the web scripting language of choice.")) {
  print "A match was found.";
} else {
  print "A match was not found.";
}

note that the forward slashes and the 'i' have been removed

Posted: Tue Jun 25, 2002 11:29 pm
by jason
Yes, that is because preg and ereg use two different types of regex's, preg functions are PCRE, or Perl Compatible Regular Expressions, where as teh ereg are not.

Posted: Wed Jun 26, 2002 9:31 am
by volka
do the ereg-functions have ANY advantage?

Posted: Wed Jun 26, 2002 9:58 am
by jason
Nope, not really, unless you are used to those types of RegEx's. EREG is POSIX compliant.

PCRE is faster though, and I just stick to that.