|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-23 10:47 UTC] ninzya at inbox dot lv
Description: ------------ It would be great if dirname() function had a second parameter, let's say - uint $level, which would mean "how many path levels to strip off". By default this parameter could be set to 1 to not to break the backwards compatibility. Reproduce code: --------------- <?php $path ='/var/www/localhost/public_html/tpl/'; echo dirname( $path);// /var/www/localhost/public_html echo dirname( $path, 2);// /var/www/localhost echo dirname( $path, 3);// /var/www/ echo dirname( $path, 4);// /var echo dirname( $path, 5);// . echo dirname( $path, 6);// . ?> Expected result: ---------------- Expect this feature to be implemented Actual result: -------------- - PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
Oops, you're right. However, if you want to make it strip multiple levels, you can simply apply the function multiple times, or write a function to apply it so: function dirname_multilevel($path, $level = 1) { return $level ? dirname_mutilevel(dirname($path), $level - 1) : $path; }