note 44897 added to function.strpos
| From: | php dot at dot wwwcrm dot dot dot com at osu1 dot php dot net | Date: | Thu, 19 Aug 2004 17:33:04 +0000 |
| Subject: | note 44897 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79822@lists.php.net to get a copy of this message | ||
Watch out for type!
The following code will return "not matched", which is a little counter-intuitive.
<?php
$val1=123;
$val2="123,456,789";
if (strpos($val2, $val1)!==false) echo "matched";
else echo "not matched";
?>
When $val1 is cast to string, it behaves as you might expect:
<?php
$val1=(string)123;
$val2="123,456,789";
if (strpos($val2, $val1)!==false) echo "matched";
else echo "not matched";
?>
Hope this saves someone the couple of hours that it took me to spot it :-)
Regards,
Alex Poole
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44897
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44897&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44897&report=yes
Search -- http://master.php.net/manage/user-notes.php