About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Regular Expressions...

   Browse by title articles:
   What is hot:

Accessing Arrays

Sorting Arrays

Push and Pop

Exploding and Imploding

Regular Expressions

Metacharacters

Search Engine Robots - How They Work, What They Do
Basic and Not so Basic "Function" Features Using PHP
5 Ways to Speed Up Your PC
Does The Color of Your Site Matter?
Prev articles12345678 9 101112Next articles



Regular Expressions


Computer & I'net articlesRegular Expressions

by David Stanley    



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!



-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Interest compare




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com