Find last character in a string in PHP

前端 未结 7 1878
粉色の甜心
粉色の甜心 2020-12-15 09:02

I\'m doing some url rewriting in PHP and need to find URLS with a slash at the end and then do a 301 redirect. I thought there\'d be a simple PHP function to find last stri

7条回答
  •  自闭症患者
    2020-12-15 09:44

    $string[strlen($string)-1] gives you the last character.

    But if you want to strip trailing slashes, you can do $string = rtrim($string, '/');. If there is no trailing slash, $string will remain unchanged.

提交回复
热议问题