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
eregi
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 :
$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!";
}
?>
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 :
$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!";
}
?>
Success, the pattern was found!

