PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




ereg

Name

ereg — Performs POSIX regular expression match against the specified string.

Synopsis

string ereg(pattern, subject[, matches]);
string pattern: Regex pattern to match
string subject: String to search using the pattern
array matches (optional): Array in which to store the search results

Returns

FALSE if no match is found; otherwise, the length of the full match if the matches parameter is specified or 1 if it's not specified

Description

Searches a string for a regular expression according to the specified POSIX regex pattern. If the matches parameter is supplied, it should be a valid variable, such as $matches, since the function forces it to be passed by reference. Existing contents of this variable are overwritten with the results of the successful search. $matches[0] contains the text from the subject string that matched the full pattern. $matches[1] through $matches[9] contain the pieces of the subject string matching the parenthesized subpatterns, even though more or fewer than nine parenthesized subpatterns may actually have matched. Subpatterns 10 and above are discarded silently. If no matches are found, matches is not altered by this function.

The eregi() function works in the same manner but isn't case-sensitive. This function uses the POSIX regular expression syntax, not to be confused with the Perl regular expression syntax.

See also

See also eregi() , preg_match() , preg_match_all()

Example

Example 1122. Simple string match

$string = "The quick brown fox jumped over the lazy dog";
if (!ereg("Quick Brown",$string)) {
   echo "Didn't find the pattern in '$string'.\n";
}
else {
   echo "Found the pattern.\n";
}
if (!ereg("([qQ]uick [bB]rown)",$string,$part)) {
   echo "Didn't find the patten in '$string'.\n";
}
else {
   echo "Found $part[1].\n";
}



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.