I have a function to grab the current url – found here: http://webcheatsheet.com/php/get_current_page_url.php – and I am trying to look for a string – WordPress category slug – inside of it:
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
//echo $pageURL;
if (strstr($pageURL, 'pro'))
{
echo "cool!";}
else {echo "bummer";}`
The url $pageURL when echoed does have the full url with the pro as part of the url, but bummer is echoed anyways meaning either my if statement is of or that my strstr does not work. What is it?
If that portion of code is copied exactly from your code, then you are not setting the
$pageURL.Before your condition you should call
to make sure you are searching the word “pro” inside the actual url.
If you have code inbetween the condition and your function declaration, then take a look at the details regarding
strstrand what evaluates toFALSEstrstrReturns the portion of string, orFALSEif needle is not found.In PHP when converting to boolean, the following values are considered FALSE:
the boolean
FALSEitselfthe integer
0(zero)the float
0.0(zero)the empty string, and the string “
0“an array with zero elements
an object with zero member variables (PHP 4 only)
the special type
NULL(including unset variables)SimpleXML objects created from empty tags