在smarty中检索链接的一部分

在smarty中检索链接的一部分

问题描述:

I have the following link:

http://anydomainname.com/user/username/about

I know that $smarty.server.REQUEST_URI will return user/username/about.

But I can't find a way to return the latest part of my link which is about.

How can I return it? I prefer a solution that does not require me to alter or add new functions in .php files.

我有以下链接: p>

http://anydomainname.com/user/username/about p> blockquote>

我知道 $ smarty.server.REQUEST_URI code>将返回 user / username / about code>。 p>

但是 我找不到一种方法来返回我的链接的最新部分,即 about code>。 p>

我该如何归还? 我更喜欢不需要在.php文件中更改或添加新功能的解决方案。 p> div>

Here's an alternative to Marcin's answer using PHP's basename() function instead of substr/strrpos:

{$smarty.server.REQUEST_URI|basename}

You can use:

{$smarty.server.REQUEST_URI|substr:($smarty.server.REQUEST_URI|strrpos:'/'+1)}

It finds the last / in this string and return everything after it.

It is working in Smarty 3.1.19