[英]How to get segment of uri after translation?
如何从 uri 例如: /en/joe-doe/contact
到joe-doe/contact
? 语言是动态的,可以改变。
Uri: /en/joe-doe/contact/form
通缉 uri : joe-doe/contact/form
您不需要为此使用正则表达式。 只需使用str_replace
并从字符串中删除/en/
。
PHP代码,
$s = "/en/joe-doe/contact";
echo str_replace('/en/', '', $s);
输出,
joe-doe/contact
但是如果 start 中的字符串是动态的,那么你可以使用这个正则表达式,
^/[^/]*/
并将其替换为空字符串。
PHP代码,
$s = "/somedynamic string/joe-doe/contact";
echo preg_replace('~/[^/]*/~', '', $s);
印刷,
joe-doe/contact
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.