![]() |
|
| |||||||
| Notices |
| mySQL & PHP Discussions, information and help with mySQL and PHP. |
![]() |
| | LinkBack | Thread Tools |
|
#1
| ||||
| ||||
| Hi, I read a few articles on ereg and eregi, but im having trouble understanding this. I saw a few examples such as ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$ and ([[:digit:]]|[~`!@#$%^&*()_=+{}|\:;"/?,]|[|]|-)+ and so on..can someone help me break this down?
__________________ No its not Fowbers its foobers :D |
|
#2
| ||||
| ||||
| As you probably know from your articles, ereg and eregi are functions that search a string for a defined variable or group of variables Once found, then you create code to do something. For instance. Lets say you wanted to check your e-mail to make sure that it had the standard format of blahblah@whatever.com So you have to create a block of what is exceptable to meet that standard and test for it. If(! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email)) { Do what ever here; } So the code above says IF the sting in $email does not have letters or numbers plus and @ symbol followed by a . and then followed by a set of letters or numbers followed by .com - DO what ever here So- in nut shell, it allows you to test a string and make sure it conforms to your own needed criteria. The difference between ereg() and eregi(). ereg() does a case sensitive search and eregi() is a case insensitive. Andy
__________________ My diamond in the rough - www.123gpp.com * Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!) |
|
#3
| ||||
| ||||
| Just to add a little more.. both use a format called regex to check a string for certain characters if you are looking for more of a breakdown of what does what, I did a google search and this might help http://ysomeya.hp.infoseek.co.jp/eng-quick_regex.html
__________________ Register/Login Script Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script |
|
#4
| ||||
| ||||
| ok let me see if I got this. If(! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email)) ereg means that the search is case sensitive (' starts the function [ starts the first set of characters A-Za-z0-9_- is allowing only characters A-Za-z0-9_- ] ends the first set +\@ means that the @whatever is next +/. means after @whatever they must have a . then [A-Za-z0-9_-] is com, so what we have so far is blahblah24@whatever.com, correct? then the +', $email means that this function is for the $email variable only? then of course the closing ')) Thnx Matt
__________________ No its not Fowbers its foobers :D |
|
#5
| ||||
| ||||
| Bravo! Couldn't have done better myself. Andy
__________________ My diamond in the rough - www.123gpp.com * Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!) |