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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -