note 115135 deleted from function.strpos by cmb
| From: | cmb@php.net | Date: | Sun, 02 Jun 2019 08:04:33 +0000 |
| Subject: | note 115135 deleted from function.strpos by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211170@lists.php.net to get a copy of this message | ||
Note Submitter: mail at nikha dot org
----
What the manual says about "if $needle is not a string" is confusing.
in fact, strpos() compares strings, and nothing else.
Example:
$haystack = "123456789";
$needle = 2;
strpos($haystack, $needle) returns boolean false
$needle = "2";
strpos($haystack, $needle) returns 1;
My real life problem were timestamps. I had a list of timestamps like this:
"!<timestamp0>!<timestamp1>!<timestamp2>..." Then I tried to find out,
wheter an actualy by "mktime()" generated timestamp is found in this list or not. But
strpos() returned always boolean 0, because mktime() results are integers.
It worked only like this:
strpos($timestamp_list, strval($mktime_result))
may be helpfull for others...
Niklaus