Find last character in a string in PHP

前端 未结 7 1913
粉色の甜心
粉色の甜心 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 10:04

    You could preg_replace() a / at the end of the subject

    $url = 'http://domainx.com/characters/';
    $url = preg_replace('/(?:\/)$/', '', $url);
    

提交回复
热议问题