Re: [PHP] problem with if and exact match
On 03/15/2011 07:30 AM, Steve Staples wrote: > > Wouldn't this be better to use, as it is meant to search for the string > inside the string? (use use regex) > > if(stristr($name, 'Jackson')) > { > echo "String is in String"; > } > else > { > echo "Failed"; > } > > http://ca.php.net/manual/en/function.strstr.php (case sensative) > http://ca.php.net/manual/en/function.stristr.php (case insensative) > > Steve. > >From your link: Note: If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] problem with if and exact match
On Tue, 2011-03-15 at 01:20 -0400, Jack wrote: > Thanks everyone... great examples...works ( both methods ) > > Thanks! > Jack > > > -Original Message- > > From: Alexis Antonakis [mailto:ad...@antonakis.co.uk] > > Sent: Tuesday, March 15, 2011 1:10 AM > > To: Jack > > Subject: Re: [PHP] problem with if and exact match > > > > http://php.net/manual/en/function.preg-match.php > > > > On 14/03/11 23:02, Jack wrote: > > > I want to be able to match if a string is contained within the string > > > I am evaluating. > > > > > > > > > > > > I know that if ( $name == "xxjacksonxx"); based on the below would be > > true. > > > > > > But I want to be able to say if "jackson" is contained within $name > > > that it's a match. > > > > > > > > > > > > I tried the below without success.. > > > > > > Not getting the operand properly.. > > > > > > > > > > > > > > > > > > > > > > > $name = "xxjacksonxx"; > > > > > > > > > > > > if ( preg_match($name, "jackson")) { > > > > > > print "true"; > > > > > > > > > > > > } else { > > > > > > > > > > > > print "false"; > > > > > > } > > > > > > > > > > > > ?> > > > > > > > > > > > > Thanks! > > > > > > Jack > > > Wouldn't this be better to use, as it is meant to search for the string inside the string? (use use regex) if(stristr($name, 'Jackson')) { echo "String is in String"; } else { echo "Failed"; } http://ca.php.net/manual/en/function.strstr.php (case sensative) http://ca.php.net/manual/en/function.stristr.php (case insensative) Steve. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with if and exact match
strpos example is much faster though On Tue, Mar 15, 2011 at 7:20 AM, Jack wrote: > Thanks everyone... great examples...works ( both methods ) > > Thanks! > Jack > > > -Original Message- > > From: Alexis Antonakis [mailto:ad...@antonakis.co.uk] > > Sent: Tuesday, March 15, 2011 1:10 AM > > To: Jack > > Subject: Re: [PHP] problem with if and exact match > > > > http://php.net/manual/en/function.preg-match.php > > > > On 14/03/11 23:02, Jack wrote: > > > I want to be able to match if a string is contained within the string > > > I am evaluating. > > > > > > > > > > > > I know that if ( $name == "xxjacksonxx"); based on the below would be > > true. > > > > > > But I want to be able to say if "jackson" is contained within $name > > > that it's a match. > > > > > > > > > > > > I tried the below without success.. > > > > > > Not getting the operand properly.. > > > > > > > > > > > > > > > > > > > > > > > $name = "xxjacksonxx"; > > > > > > > > > > > > if ( preg_match($name, "jackson")) { > > > > > > print "true"; > > > > > > > > > > > > } else { > > > > > > > > > > > > print "false"; > > > > > > } > > > > > > > > > > > > ?> > > > > > > > > > > > > Thanks! > > > > > > Jack > > > > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
RE: [PHP] problem with if and exact match
Thanks everyone... great examples...works ( both methods ) Thanks! Jack > -Original Message- > From: Alexis Antonakis [mailto:ad...@antonakis.co.uk] > Sent: Tuesday, March 15, 2011 1:10 AM > To: Jack > Subject: Re: [PHP] problem with if and exact match > > http://php.net/manual/en/function.preg-match.php > > On 14/03/11 23:02, Jack wrote: > > I want to be able to match if a string is contained within the string > > I am evaluating. > > > > > > > > I know that if ( $name == "xxjacksonxx"); based on the below would be > true. > > > > But I want to be able to say if "jackson" is contained within $name > > that it's a match. > > > > > > > > I tried the below without success.. > > > > Not getting the operand properly.. > > > > > > > > > > > > > > > $name = "xxjacksonxx"; > > > > > > > > if ( preg_match($name, "jackson")) { > > > > print "true"; > > > > > > > > } else { > > > > > > > > print "false"; > > > > } > > > > > > > > ?> > > > > > > > > Thanks! > > > > Jack > > > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with if and exact match
On 15/03/2011, at 6:02 PM, Jack wrote: > I want to be able to match if a string is contained within the string I am > evaluating. > > > > I know that if ( $name == "xxjacksonxx"); based on the below would be true. > > But I want to be able to say if "jackson" is contained within $name that > it's a match. > > > > I tried the below without success.. > > Not getting the operand properly.. > > > > > > > $name = "xxjacksonxx"; > > > > if ( preg_match($name, "jackson")) { > > print "true"; > > > > } else { > > > > print "false"; > > } > > > > ?> > > > > Thanks! > > Jack if(strpos($name, 'jackson') !== false) { true } You can use stripos for case-insentive matching. Using regex functions when you don't need the power is overkill and slower. Your call to preg_match wasn't working because you need your search term first, and it needs proper delimiters. --- Simon Welsh Admin of http://simon.geek.nz/ Who said Microsoft never created a bug-free program? The blue screen never, ever crashes! http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with if and exact match
Try If(preg_match("/Jackson/i", $name)) {echo 'match'; }else{ echo 'fail'; } Richard Buskirk Sent from my iPhone On Mar 15, 2011, at 1:02 AM, "Jack" wrote: > I want to be able to match if a string is contained within the string I am > evaluating. > > > > I know that if ( $name == "xxjacksonxx"); based on the below would be true. > > But I want to be able to say if "jackson" is contained within $name that > it's a match. > > > > I tried the below without success.. > > Not getting the operand properly.. > > > > > > > $name = "xxjacksonxx"; > > > > if ( preg_match($name, "jackson")) { > > print "true"; > > > > } else { > > > > print "false"; > > } > > > > ?> > > > > Thanks! > > Jack > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php