How to split a path properly in PHP

前端 未结 4 676
别那么骄傲
别那么骄傲 2021-02-13 14:52

What is the best way to do the following:

I get a path with an AJAX request

e.g. dir1/dir2/dir3/dir4

I need to present it like this on my we

4条回答
  •  梦毁少年i
    2021-02-13 15:23

    if all you need to do is explode by forward slash there is a simple solution that works everytime.

    check this out

    $path = 'dir1/dir2/dir3/dir4';
    
    $array = explode('/', ltrim($path, '/'));
    
    print_r($array);
    

    enjoy :D

提交回复
热议问题