Remove unnecessary slashes from path

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

    You could use the build-in function realpath() for stripping slashes of existing files. But you will always end up with a canonicalized absolute pathname.

    
    

    Please note that this function returns an error if the file does not exist.

    Some important remarks from the docs:

    realpath() expands all symbolic links and resolves references to '/./', '/../' and extra '/' characters in the input path and returns the canonicalized absolute pathname.

    And

    On windows realpath() will change unix style paths to windows style.

提交回复
热议问题