note 126105 added to function.pathinfo

From: Date: Tue, 25 May 2021 15:27:48 +0000
Subject: note 126105 added to function.pathinfo
Groups: php.notes 
Request: Send a blank email to php-notes+get-216424@lists.php.net to get a copy of this message
unexpected, but longtime (all versions?) consistent, behaviour with trailing slash (Linux): with Linux I am used, to add a trailing slash, or just to keep that of the command line completion by [TAB], to avoid mistyping a path on cp or mv with a same filename instead of a directory using CLI '$ php -a' the result is in the next line (but can also be done by script, webserver, etc.) <?php // using php tags here only for syntax highlighting // assuming getcwd() is /home/USER/ with existing subdir www.2021-05/ // cause path must exist, else 'false' php > echo realpath('www.2021-05/'); /home/USER/www.2021-05 php > var_dump(pathinfo('/home/USER/www.2021-05/')); array(4) { ["dirname"]=> string(10) "/home/USER" ["basename"]=> string(11) "www.2021-05" ["extension"]=> string(7) "2021-05" ["filename"]=> string(3) "www" } php > echo dirname('/home/USER/www.2021-05/'); /home/USER php > echo basename('/home/USER/www.2021-05/'); www.2021-05 ?> with my own written functions, I would first split path from filename at the _last_ slash (plus some extra for root-slash only); which would find NO filename, only dirname path, in that example for cross reference: once reported on Win2k -- https://bugs.php.net/bug.php?id=41834 said to be heritage -- https://bugs.php.net/bug.php?id=81079 ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 2003:ee:9f2b:d2ee:eef4:bbff:fe61:4310) ---- Manual Page -- https://php.net/manual/en/function.pathinfo.php Edit -- https://main.php.net/note/edit/126105 Del: integrated -- https://main.php.net/note/delete/126105/integrated Del: useless -- https://main.php.net/note/delete/126105/useless Del: bad code -- https://main.php.net/note/delete/126105/bad+code Del: spam -- https://main.php.net/note/delete/126105/spam Del: non-english -- https://main.php.net/note/delete/126105/non-english Del: in docs -- https://main.php.net/note/delete/126105/in+docs Del: other reasons-- https://main.php.net/note/delete/126105 Reject -- https://main.php.net/note/reject/126105 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216424) next »