PHP Snippet 1:
function get_current_url()
{
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "??") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$url = get_current_url();
if (strpos($url, '/store/') !== false) {
echo 'found';
}else{
echo 'not found';
}
PHP Snippet 2:
// input url string
$url = 'https://www.website.com.au/store/brand/';
$path_to_check_for = '/store/';
// check if /store/ is the url string
if ( strpos($url, $path_to_check_for) !== false ) {
// Url contains the desired path string
// your remaining code to do something in case path string is there
} else {
// Url does not contain the desired path string
// your remaining code to do something in case path string is not there
}