The php strstr() is a great method to retrieve part of a string after a certain point.Here is an example to retrieve a url and get the page title for other purposes.
$page_URL = ‘http’;
if ($_SERVER[“HTTPS”] == “on”) {$page_URL .= “s”;}
$page_URL .= “://”;
if ($_SERVER[“SERVER_PORT”] != “80”) {
$page_URL .= $_SERVER[“SERVER_NAME”].”:”.$_SERVER[“SERVER_PORT”].$_SERVER[“REQUEST_URI”];
} else {
$page_URL .= $_SERVER[“SERVER_NAME”].$_SERVER[“REQUEST_URI”];
}
return $page_URL;
}
$var=my_page_URL();
//This shows the url
echo $var;
//strstr gets all string after a certain point
$domain = strstr($var, ‘mysitename’); //will output mysitename.com/mypage.php
echo $domain; // prints mysitename.com/mypage.php whether the url had http:, www., etc
//now get rid of mysitename.com
$cms_page_title= str_replace(‘mysitename.com/’, ”, $domain);
echo $cms_page_title; //now we get mypage.php
?>
© 2018 ALL Rights Reserved | Sitemap
Vancouver | North Vancouver | Burnaby | Richmond | Coquitlam | Port Coquitlam | Surrey | Langley | Maple Ridge | Mission | Abbotsford | Kamloops | Kelowna | Victoria | Squamish | Whistler | Pemberton