Webmaster

References : PHP 4.0

 | Index | 
 | Input/Output | General data handling | Array handling | String handling | Data conversion | Regular expressions | Time and date | PHP calendars | Configuration | 
 | All functions | 

Regular expressions

Regular expressions allow us to look for some specific patterns in our data. A regular expression, a.k.a. regexp, enables us to describe a sub-string to compare with a piece of data.

ereg(pattern, string, match_array) | ereg_replace(pattern, replacement, string) | eregi(pattern, string, match_array) | eregi_replace(pattern, replacement, string)

ereg(pattern, string, match_array)
The pattern to be compared can contain various types of special characters and is parsed according to specific regexp syntactical rules. The function searches the second argument for the given regexp. The third argument is optional and specifies an array which collects all matches. The function's result is TRUE if there is at least one match.
 
Example<?
  ereg("^(.+)/([0-9])\.([0-9]+)",
    $HTTP_USER_AGENT, $occur)
?>
 
 Top
ereg_replace(pattern, replacement, string)
Searches the third argument for the pattern given as the first argument and replaces all matches with the third argument. The new string is returned. If there is no match, the string returned is the same as the original one.
 
Example<?
  $searched = "Text with \n line \n breaks.";
  print(ereg_replace("\n", "<br>", $searched));

?>
 
 Top
eregi(pattern, string, match_array)
This function is similar to ereg, except that the search is case-insensitive.
 
 Top
eregi_replace(pattern, replacement, string)
This function is similar to ereg_replace, except that case distinction is ignored.
 
 Top

 | Index | 
 | Input/Output | General data handling | Array handling | String handling | Data conversion | Regular expressions | Time and date | PHP calendars | Configuration | 
 | All functions |