How to split a path properly in PHP

前端 未结 4 673
别那么骄傲
别那么骄傲 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

    Something like this maybe (if I got your intention right):

     $chunk) {
        $output[] = sprintf(
            '%s',
            implode('/', array_slice($chunks, 0, $i + 1)),
            $chunk
        );
    }
    
    echo implode(' >> ', $output);
    

    Output:

    dir1 >> 
    dir2 >>
    dir3 >>
    dir4
    

提交回复
热议问题