Re: Best way to check for some certain text in a string

From: Date: Wed, 21 Aug 2002 14:36:59 +0000
Subject: Re: Best way to check for some certain text in a string
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-113469@lists.php.net to get a copy of this message
José Jeria wrote:
"Bogdan Stancescu" <mgv@canad.ro> wrote in message news:3D639BB2.9050508@canad.ro...
If you don't need regexps, use strpos. Make sure you read the
Can you give me any particular reason why strpos is better? http://php.weblogs.com/discuss/msgReader$1838
documentation though - if $nav->userAgent starts with "search for this", your code will return false.
Yeah, that was a typo when i copy and pasted.
Bogdan José Jeria wrote:
I want to find a certain text in a string and i want it to return me a boolean. What is the best thing to do this?
a) ereg("search for this", $string);                            //
returns
int(1) if true, bool(false) if not
b) strpos($nav->userAgent, "search for this") > 0    // gives me a
boolean
directly Any tips of which one I should use? /José Jeria


« previous php.general (#113469) next »