Remove unnecessary slashes from path

后端 未结 6 590
温柔的废话
温柔的废话 2021-02-06 08:00
$path = \'/home/to//my///site\';

I am trying to remove unnecessary forward slashes / from the path above

I am trying to get this

6条回答
  •  甜味超标
    2021-02-06 08:46

    if someone wants to remove extra slashes from URL without removing first two slashes after http/https:

    $url = preg_replace('/([^:])(\/{2,})/', '$1/', $url); 
    

    (thanks to ツ Liverbool how to remove multiple slashes in URI with 'PREG' or 'HTACCESS')

提交回复
热议问题