PHP How to remove last part of a path

后端 未结 5 1984
太阳男子
太阳男子 2020-12-01 17:51

I have a path like this:

parent/child/reply

How do I use PHP to remove the last part of the path, so that it looks like this:

pare

5条回答
  •  天命终不由人
    2020-12-01 18:28

        preg_replace("/\/\w+$/i","",__DIR__);
         # Note you may also need to add .DIRECTORY_SEPARATOR at the end.
    

提交回复
热议问题