| Home > Computer & I'net > Character Classes... |
|
|
|||||||||||||||
|
|
|||||||||||||||
|
||||||||||||||||
Character Classes | |||||||||||||||||||||||||
Classes are created by putting a set of characters within the [square] brackets. Searching for a vowel may be done by using [aeiou] for example. The search will take each letter and do a search for it in the specified area. Using a dash inside a class is a shortcut to specify "between". Using [a-f] will do a search for any lowercase letter between a to f. Combinations can also be entered in classes. Using [a-zA-Z] will do a search for any lowercase or uppercase letter. This would also create the same result as using the [[:alpha:]] class in this example. The ^ symbol has a different effect inside the square brackets. It will do a search that does not include the pattern specified. Using [^z] searches for any character other than lower case z. Using this new information, you can revise the email address checker script like so... <?php $value1 = "here@there.com"; $value2 = "here@there.ca"; $value3 = "here@therecom"; $value4 = "blah@noplace.yahoo"; $value5 = "cool@site.n"; $search_pattern = "^([0-9a-z]+)([0-9a-z.-_]+)@([0-9a-z.-_]+)(.[a-z]{2,3}$)"; $result1 = eregi($search_pattern,$value1); $result2 = eregi($search_pattern,$value2); $result3 = eregi($search_pattern,$value3); $result4 = eregi($search_pattern,$value4); $result5 = eregi($search_pattern,$value5); if ($result1) {echo "one is true. ";} else {echo "one is false. ";} if ($result2) {echo "two is true. ";} else {echo "two is false. ";} if ($result3) {echo "three is true. ";} else {echo "three is false. ";} if ($result4) {echo "four is true. ";} else {echo "four is false. ";} if ($result5) {echo "five is true. ";} else {echo "five is false. ";} ?> Results : one is true. two is true. three is false. four is false. five is false. Here is the breakdown of the search pattern...
We did not have to enter the capital letters for searching because the eregi is not case sensitive. ----------------- Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission. | |||||||||||||||||||||||||
| Articles |
•Auto & Trucks•Business•Computer & I'net·General·Apache·CSS·Database·Hardware·HTML·Javascript&DHTML·Linux·MySQL·Operating System·Perl / CGIPHP·Programming·Publishing·Search Engines·Software Problems·SSI·Tips & Tricks·Utilities·Web Design•Family•Food & Drink•Gardening•Health•Other•Pets•Psychology•Spiritual•Travel•Women |
| Calculators |
|