PHP - 去除 URL 以获取标签名称 [英] PHP - strip URL to get tag name

查看:31
本文介绍了PHP - 去除 URL 以获取标签名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果匹配,我需要使用 PHP 去除 URL 以将类添加到链接.

I need to strip a URL using PHP to add a class to a link if it matches.

网址如下所示:

http://domain.com/tag/tagname/

如何去除 URL 以便只剩下 "tagname"?

How can I strip the URL so I'm only left with "tagname"?

所以基本上它去掉了最后的 "/" 和开始的 "http://domain.com/tag/"

So basically it takes out the final "/" and the start "http://domain.com/tag/"

推荐答案

为您的网址

http://domain.com/tag/tagname/

获取"tagname"的PHP函数称为basename():

The PHP function to get "tagname" is called basename():

echo basename('http://domain.com/tag/tagname/');   # tagname

这篇关于PHP - 去除 URL 以获取标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆