php - strpos() returning false, when needle is in haystack -
i having trouble longer func wrote, broke down , seems strpos() function.
even though needle present in haystack returns false, life of me cant work out why, oddly though if change needle "sam" in becomes true.. idea why ?
function verify_url($url) { if (strpos($url, "http://")) { return $url; } else { echo "error"; } } $url = "http://sam.com"; echo verify_url($url);
it returning 0, not false. in if test php evaluates integer value 0 boolean value false.
use strpos($url, "http://") !== false check both value , data type. called strict comparison.
manual: comparison operators , strpos().
Comments
Post a Comment