PHP检查Url并打印默认参数
我有多语言系统的Url结构,如下所示: 对于默认语言,即:PHP检查Url并打印默认参数,php,Php,我有多语言系统的Url结构,如下所示: 对于默认语言,即:en(不在url中显示/检测短语言) localhost/cms localhost/cms/article/slug/etc. 还有另一种语言,比如: localhost/cms/fr localhost/cms/fr/article/slug/etc. 我的想法是: 为我的应用定义可用语言列表 定义我在以下情况下使用的默认语言:, A.没有提供任何语言(localhost/cms/users), B提供的语言未知(localhost/
en
(不在url中显示/检测短语言)
localhost/cms
localhost/cms/article/slug/etc.
还有另一种语言,比如:
localhost/cms/fr
localhost/cms/fr/article/slug/etc.
我的想法是:
localhost/cms/users
),
B提供的语言未知(localhost/cms/fr/users
)en
)和routableURI,
没有任何语言的URI(例如:cms/用户)function urlss(){
$uri = $_SERVER['REQUEST_URI'];
$languages = ['en', 'fr', 'es', 'de'];
// this is my default language
$defaultLang = 'en';
// $currentLang is the language I'll use to show the contents
$currentLang = $defaultLang;
$uri = ltrim(rawurldecode($uri), '/');
$parts = explode('/', $uri);
if( ! empty($parts) && in_array(strtolower($parts[0]), $languages)) {
$currentLang = array_shift($parts);
}
$routableUri = implode('/', $parts);
return $routableUri;
}
我的代码输出默认语言:(假输出)不工作
选中:localhost/cms/
或localhost/cms/users/
输出为:cms/
或cms/users/
另一种语言的输出:(true输出)工作为true
检查:localhost/cms/fr/
输出为cms/fr/
或localhost/cms/fr/users/
输出为:cms/fr/users/
我如何打印我的默认语言,而不在url中添加/检测这样的短语言名称
Check:
localhost/cms
输出为:cms/en
或Checklocalhost/cms/users/
输出为:cms/en/users/
可能将它们存储在Cookie中?@BARNI:Belike,但在这种情况下,我添加到路由类中以获得路由url。