是否有允许我检查URL是否包含特定路径的if语句?
在我的特殊情况下(使用wordpress),我试图检查网址是否包含// https://www.website.com.au/store/brand/,所以在这条路径之后可能会有一些东西.
谢谢你的帮助!
发布于 2018-10-13 10:38:52
我建议使用WordPress函数,如is_singular、is_tax等。
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';
}https://stackoverflow.com/questions/52791916
复制相似问题