Reputation: 1186
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?
Upvotes: 0
Views: 181
Reputation: 1590
If that portion of code is copied exactly from your code, then you are not setting the $pageURL
.
Before your condition you should call
$pageURL=curPageURL();
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 strstr
and what evaluates to FALSE
strstr
Returns the portion of string, or FALSE
if needle is not found.
In PHP when converting to boolean, the following values are considered FALSE:
the boolean FALSE
itself
the 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
Upvotes: 1
Reputation: 1770
Use this it will help you
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first; // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz
Upvotes: 0