PHP - strip URL to get tag name

前端 未结 4 835
耶瑟儿~
耶瑟儿~ 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条回答
  •  孤独总比滥情好
    2021-01-28 06:40

    As an alternative to the substring based answers, you could also use a regular expression, using preg_split to split the string:

    
    

    (The reason for the -2 is because due to the ending /, the final element of the array will be a blank entry.)

    And as an alternate to that, you could also use preg_match_all:

    
    

提交回复
热议问题