Find last character in a string in PHP

前端 未结 7 1877
粉色の甜心
粉色の甜心 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);
    
    0 讨论(0)
提交回复
热议问题