pahunrepublic Posted June 24, 2010 Share Posted June 24, 2010 Hi Everyone! There is this code: eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email); with eregi()function. It works fine but I don't understand what does '^' , '$' , '\.' 'symbols mean in the function. What do they do? Other thing: I've heard that ereg() function will be deprecated in PHP6. Any alternatives?? I've heard preg_match() is the answer because it works the same way but I don't know how to use it. For example this line: if(!eregi("^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$",$phone)) How would you code it down in preg_match() Thanx the answers in advance folks!! Quote Link to comment https://forums.phpfreaks.com/topic/205749-can-someone-explain-ereg-to-me/ Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 There are some pretty good regex tutorials (which I rely on, since I'm horrible with regex) that come up in a google search. As far as deprecation; from the PHP manual: This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. Quote Link to comment https://forums.phpfreaks.com/topic/205749-can-someone-explain-ereg-to-me/#findComment-1076679 Share on other sites More sharing options...
premiso Posted June 24, 2010 Share Posted June 24, 2010 Ereg is depreciated. It is better to use preg_match which would be the equivalent. As for what the special characters are, well see my signature for links to resources on Regular Expressions. if (!preg_match('~^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$~', $phone)) { Would be the "equivalent" to what you are doing. The ~ are delimiters, it does not have to be ~ it could be # / etc depending on your taste. The $ denotes the end of a string and the ^ denotes the start (when not used inside of parans). So the start of the string has to start with 3 numbers 0-9 and the end has to end with 1-10 numbers 0-9 or else it is not matched. Quote Link to comment https://forums.phpfreaks.com/topic/205749-can-someone-explain-ereg-to-me/#findComment-1076681 Share on other sites More sharing options...
Daniel0 Posted June 24, 2010 Share Posted June 24, 2010 Also have a look at http://dk.php.net/manual/en/reference.pcre.pattern.syntax.php Quote Link to comment https://forums.phpfreaks.com/topic/205749-can-someone-explain-ereg-to-me/#findComment-1076698 Share on other sites More sharing options...
pahunrepublic Posted June 24, 2010 Author Share Posted June 24, 2010 Ereg is depreciated. It is better to use preg_match which would be the equivalent. As for what the special characters are, well see my signature for links to resources on Regular Expressions. if (!preg_match('~^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$~', $phone)) { Would be the "equivalent" to what you are doing. The ~ are delimiters, it does not have to be ~ it could be # / etc depending on your taste. The $ denotes the end of a string and the ^ denotes the start (when not used inside of parans). So the start of the string has to start with 3 numbers 0-9 and the end has to end with 1-10 numbers 0-9 or else it is not matched. Thanx Quote Link to comment https://forums.phpfreaks.com/topic/205749-can-someone-explain-ereg-to-me/#findComment-1076804 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.