shadowline
Exploding and Imploding << Regular Expressions >> Metacharacters
Regular expressions are matching patterns. First you tell the script what you want to search for and where, then it will try to find it. If the search is a success, a TRUE value will appear. If the search is a failure, a FALSE value will appear.

A pattern is what you are looking for in a specific area. It can be a word, a letter, whatever. For our examples, we will use the letter z.

There are two commands to use for searching. ereg for doing a case sensitive search (for specifically a lower or upper case letter) or eregi for doing a case insenitive search (searching for either a lower or upper case letter).

The ereg command takes two properties. One for the pattern to search for, the second for the search area.

ereg
<?php
$pattern = "z";
$search_area = "My car goes ZOOM.";
$search_result = ereg($pattern,$search_area);

if ($search_result){
// print this if there is a true result.
echo "Success, the pattern was found!";
} else {
// print this if there is a false result.
echo "Failure, the pattern was not found!";
}
?>
result :
Failure, the pattern was not found!

eregi
<?php
$pattern = "z";
$search_area = "My car goes ZOOM.";
$search_result = eregi($pattern,$search_area);

if ($search_result){
// print this if there is a true result.
echo "Success, the pattern was found!";
} else {
// print this if there is a false result.
echo "Failure, the pattern was not found!";
}
?>
result :
Success, the pattern was found!
Exploding and Imploding << Regular Expressions >> Metacharacters
shadow

Advertise in the banner along the top, Click here!

Valid XHTML 1.0 Transitional Valid CSS! Text Link Ads
shadow
shadow