PHP » Strings » eregi()

Syntax:
int eregi(string pattern, string s [, array matches])
pattern
Pattern to match against.
s
The string.
matches
Array to return matches in.

Case insensitive pattern matching with regular expressions.

This function has been deprecated as of PHP 5.3.0.

eregi() works just like ereg() but is case insensitive. It returns the first match of a regular expression pattern in a string. The optional "matches" parameter is an array in which the matches will be returned. The first element of the array is the portion of the string that the whole pattern matches. Subsequent elements are the submatches from the use of parentheses.

Examples

Code:
<?php

$s = "Coding PHP is fun.";

if (ereg("php", $s, $matches)) {
   print_r($matches);
} else {
   print "ereg(): The pattern did not match anything";
}

print "<br><br>";

if (eregi("php", $s, $matches)) {
   print "<pre>eregi(): ";
   print_r($matches);
   print "</pre>";
} else {
   print "The pattern did not match anything";
}

?>
Output:
ereg(): The pattern did not match anything


eregi(): Array
(
   [0] => PHP
)

Explanation:

ereg() is case sensitive, while eregi() is case insensitive.

See Also: