note 473 modified in strpos by ronabop
| From: | ronabop@php.net | Date: | Wed, 13 Dec 2000 06:22:40 +0000 |
| Subject: | note 473 modified in strpos by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-8685@lists.php.net to get a copy of this message | ||
The only way I found to test for a string match on the beginning of "haystack" is to use:
if (is_int(strpos($haystack, $needle))) { }
strpos returns an empty string "" if no match is found, an integer otherwise. Therefore
tests like empty(strpos($haystack, $needle))
and
strpos($haystack, $needle) >= 0
don't work, because empty strings "" have a value and are evaluated as 0.
http://www.php.net/manual/function.strpos.php