![](/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.