Re: Strings and regular expression?

From: Date: Fri, 07 Feb 2003 21:47:45 +0000
Subject: Re: Strings and regular expression?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-134805@lists.php.net to get a copy of this message
This one time, at band camp, "1LT John W. Holmes" <holmes072000@charter.net> wrote: > > $a1="1,8,98,244,9,243,2,6,36,3,111,"; > > > > $a2="8,98,244,9,243,2,1,6,36,3,111,"; > > > > How can I exactly match "1," in both strings using one regular expression? > > (first "1" is the first element and second time in a random position)? > > if(preg_match('/(^|,)1(,|$)/',$str)) > { echo "one is found"; } if(strstr($string, '1,') == 'FALSE){ echo 'No match found'; }else{ echo 'Found a match'; } No need for costly regex Kevin -- ______ (_____ \ _____) ) ____ ____ ____ ____ | ____/ / _ ) / _ | / ___) / _ ) | | ( (/ / ( ( | |( (___ ( (/ / |_| \____) \_||_| \____) \____) Kevin Waterson Port Macquarie, Australia

« previous php.general (#134805) next »