Ok, I am trying to do an IF / else IF statement that doesn't act as i would expect. I am trying to check that a URL address someone enters for certain things. The way I have done it is probably crap but I am not that good at programming.
All the IF parts work except for this bit if (strpos($URLcheck, "http://") == false)
It is supposed to check if the URL has http:// in it. But whether it does or doesn't it still acts exactly the same way.
I even tried forcing the http:// into the URL by stripping it of http:// or https://.
When I echo the variable ($URLcheck) , it shows the URL with the http://.....so why doesn't my code work? Thanks
$URL = htmlspecialchars($_POST["URL"]);
$URLREMOVESarray = array('https//:', 'http//:');
$URLhttp = str_replace($URLREMOVESarray, "", $URL);
$URLcheck = "http://" . $URLhttp;
$URLsearchcheck2 = 'property-profile/';
$URLsearchcheckDomain = "domain";
if (strpos($URL, $URLsearchcheck2) !== false) {
echo "Test 1";
}
else if (strpos($URLcheck, "http://") == false) {
echo "Test 2";
echo $URLcheck;
}
else if (strpos($URLcheck, $URLsearchcheckDomain) == false) {
echo "Test 3";
}
else if (strpos($URLcheck, $URLsearchcheckDomain) == true) {
Continue1();
}
Update: Still no solutions to why this doesn't work? I have even copy and pasted the code from this page and it still doesn't work.
===operator. strposfalseequals0if you make comparisons without forcing the same type. Compare something with the same type with===or!==