Re: Best way to check for some certain text in a string
| From: | Bogdan Stancescu | Date: | Sat, 24 Aug 2002 01:04:03 +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-113888@lists.php.net to get a copy of this message | ||
The code he posted would return PRECISELY false. Read the code again.
Bogdan
Konstantin Vainer wrote:
The code will not really return false... it will return the _position_ which is 0 you can check it... Thats what php manual says on the point... // in PHP 4.0b3 and newer: $pos = strpos($mystring, "b"); if ($pos === false) { // note: three equal signs// not found...} // in versions older than 4.0b3: $pos = strpos($mystring, "b"); if (!is_integer($pos)) {// not found...} "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 documentation though - if $nav->userAgent starts with "search for this", your code will return false. Bogdan José Jeria wrote:returnsI 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); //booleanint(1) if true, bool(false) if notb) strpos($nav->userAgent, "search for this") > 0 // gives me adirectly Any tips of which one I should use? /José Jeria