PHP 如何删除路径的最后一部分

php
2022-08-30 15:00:12

我有这样一条路:

parent/child/reply

我如何使用PHP删除路径的最后一部分,使其看起来像这样:

parent/child


答案 1
dirname($path)

这是文档。


答案 2

dirname().您可以根据需要多次使用它

  • 获取父/子 - dirname('parent/child/reply')
  • 获取父级 - dirname(dirname('parent/child/reply'))

推荐