我想获取一个 URL 或仅一个路径,并以一致的语法去除路径之外的所有内容,例如没有结尾斜杠等。
例子:
'/categories/cameras/' => '/categories/cameras'
'http://domain.com/products/' => '/products'
'products' => '/products'
'deals/newyears/' => '/deals/newyears'
'https://domain.com/' => '/'
'https://domain.com/terms#refunds' => '/terms'
'' => '/'
任何想法如何制作一种方法来做到这一点?