PHP - strip URL to get tag name

前端 未结 4 837
耶瑟儿~
耶瑟儿~ 2021-01-28 06:24

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

The URL would look like this:

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

Ho

4条回答
  •  猫巷女王i
    2021-01-28 06:42

    Many thanks to all, this code works for me:

    $ptn = "/\//";
    $str = "http://domain.com/tag/tagname/";
    $result = preg_split($ptn, $str);
    $tagname = $result[count($result)-2];
    echo($tagname);
    

提交回复
热议问题