How to split a path properly in PHP

前端 未结 4 674
别那么骄傲
别那么骄傲 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条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-13 15:28

    Var 1

     /dir1/dir2/dir3/dir4/
           [1] => /dir1/dir2/dir3/
           [2] => /dir1/dir2/
           [3] => /dir1/
        )
        */
    
    ?>
    

    Var 2 ( Links )

    '.basename($str).'');
        while((array_pop($arr) and !empty($arr))){
            $out[] = ''.end($arr).'';
        };
    
        print_r($out);
    
        /*
        Array
        (
            [0] => dir4
            [1] => dir3
            [2] => dir2
            [3] => dir1
        )
        */
    
    ?>
    

提交回复
热议问题