![](/img/trans.png)
[英]How can I get second to last segment in URL and skip all GET queries with PHP?
[英]How can I get last segment of the string?
综述:
我需要得到这个字符串的最后一部分:
$str = 'http://localhost:8000/news/786425/fa';
// last part ^^
我怎样才能做到这一点?
说明:
我试图在URL的末尾添加一种语言(如果它不存在)或者用en
替换它(如果一种语言已经存在) 。 我的网站只支持两种语言: en
, fa
。 因此, en
和fa
应该被检测为语言。 换句话说,它们是允许的语言,其他任何东西都被视为URL的参数。
例子:
$str = 'http://localhost:8000/news/786425/fa';
// expected output: http://localhost:8000/news/786425/en
$str = 'http://localhost:8000/news/786425';
// expected output: http://localhost:8000/news/786425/en
$str = 'http://localhost:8000/news/786425/pg'; // pg is not defined as a language
// expected output: http://localhost:8000/news/786425/pg/en
$str = 'http://localhost:8000/news/786425/en';
// expected output: http://localhost:8000/news/786425/en
这是我到目前为止所尝试的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.