Remove unnecessary slashes from path

后端 未结 6 611
温柔的废话
温柔的废话 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:50

    while(strlen($path) != (strlen($path = str_replace('//','/', $path))));

    This code replaces double slashes with single slash, as long as it changes length;

提交回复
热议问题