$url = $_SERVER['REQUEST_URI'];
$url = basename($url).PHP_EOL;
switch ($url) {
case 'digital-marketing-and-seo':
$new_url = "Digital Marketing & SEO";
break;
case 'websites-digital-destinations':
$new_url = "Websites & Digital Destinations";
break;
case 'brand-identity-evolution':
$new_url = "Brand Identity & Evolution";
break;
case 'strategy-consulting':
$new_url = "Strategy & Consulting";
break;
case 'government-universities':
$new_url = "Government & Universities";
break;
case 'hospitality-travel':
$new_url = "Hospitality & Travel";
break;
case 'architecture-engineering':
$new_url = "Architecture & Engineering";
break;
case 'wine-spirits':
$new_url = "Wine & Spirits";
break;
default:
$new_url = '';
echo 'default derp';
}
所以我有这段代码,它对我不起作用。网址可以准确地说出案例中的内容,它将默认。我正在尝试获取url结构来构建一个短代码,我需要它来匹配输入的内容。
我确定如果我输入只是为$ url ='brand-identity-evolution'添加字符串变量;开关有效。我确定它是一个带有is_string函数的字符串,无法弄清楚为什么这不起作用。
答案 0 :(得分:3)
您在网址末尾添加了PHP_EOL
,因此您的所有案例都会失败,因为您未对此进行检查。删除PHP_EOL
,您就可以了。