Re: preg_match

From: Date: Mon, 29 Mar 2004 06:16:15 +0000
Subject: Re: preg_match
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-181644@lists.php.net to get a copy of this message
Jason, well, if the string is exactly how you have it, then something like this would do : $var="mailto:john@does.com)"; if(preg_match("/^(\S+)\s.+/",$var,$match)){
        $name=$match[1];
} Of course, that would exclude those addresses that might have two names, like "Tim Traver {tt@simplenet.com}" In order to get that one, you might do something like this : $var="Tim Traver {tt@simplenet.com}"; if(preg_match("/^(.+)\s\{.+/",$var,$match)){
        $name=$match[1];
} That would get anything before the bracket, excluding the space... Hope that helps... Tim. At 08:10 PM 3/28/2004, Jason Williard wrote:
I am trying to use preg_match to pull a specific piece of a variable. However, I don't have enough experience with the syntax to be able to figure this out. The variable looks like: "John {mailto:john@does.com)" All I need is the name, John. The rest can be discarded. How would I pull that bit out? Thanks, Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
SimpleNet's Back ! http://www.simplenet.com

« previous php.general (#181644) next »