View Full Version : substr() and preg_match()
hamza84
December 26th, 2003, 01:56 AM
I can't understand how to use either of these functions in PHP. Bother to help anybody?
ahmed
December 26th, 2003, 02:39 AM
whatchya trying to do exactly? can you be more specific?
http://www.php.net/preg_match
http://www.php.net/substr
hamza84
December 26th, 2003, 01:29 PM
I actually understood the substr function. I'm trying to use preg_match() for checking an email format.
ahmed
December 26th, 2003, 01:43 PM
<?php
$email = "JohnSmith@Site.com";
if ( !preg_match("/^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/", $email ) )
echo 'E-mail is invalid!';
?>I got the regex pattern off a site i googled up, I'm too dumb to write my own, lol..
MTsoul
December 26th, 2003, 02:31 PM
those kind of things scares me..
hamza84
December 26th, 2003, 04:23 PM
haha! well, mind explaining it a bit ahmed?
Marz
December 26th, 2003, 10:47 PM
He got it off a site...
Basically it's a pattern of symbols :
("/^w(?:w|-|.(?!.|@))*@w(?:w|-|.(?!.))*.w{2,3}/
Well Duh... But the symbols can mean different things... The ? marks with a : next to it I believe are conditional statments set inside of a list of patterns..I know that the w represents an escape sequence that draws forth from the current locale computer's character map.
But... Most of the othger symbols draw a blank for me.. And I'm not quite sure I want to look it up to figure it out right now ;)
hamza84
December 27th, 2003, 12:29 AM
I wish things were more clear
Jubba
December 27th, 2003, 11:08 AM
well they are called regular expressions and they are a bit difficult to understand at first.... here is a link to a really good tutorial about using them...
http://www.tote-taste.de/X-Project/regex/index.php
hamza84
December 27th, 2003, 03:39 PM
hey thanks jubba! I got more than I needed. Ain't that some christmas present eh? :D
Marz
December 29th, 2003, 01:08 AM
Hot ****... Pretty good link there Vash :) I knew some commands but now I know em all! :D
"/^[-_a-z0-9]+(\.[-_a-z0-9]+)*@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,6}$/i"
There ya go :D That's great!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.