Doc #81079 [Com]: pathinfo() unexpected path/filename separation with trailing slash
[email protected] ("punjabbestastrologer at gmail dot com") Sat, 12 Aug 2023 10:15:50 +0000
| Newsgroups | php.doc.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=81079&edit=1
ID: 81079
Comment by: punjabbestastrologer at gmail dot com
Reported by: info at kgsw dot de
Summary: pathinfo() unexpected path/filename separation with
trailing slash
Status: Verified
Type: Documentation Problem
Package: *Directory/Filesystem functions
Operating System: Linux Mint 20.1
PHP Version: 7.3.28
Block user comment: N
Private report: N
New Comment:
bestastrologernearyou.wordpress.com/
bestastrologerinamritsar.blogspot.com/
Previous Comments:
------------------------------------------------------------------------
[2023-08-12 10:14:22] astro258shastri at gmail dot com
Great info! I recently came across your blog and have been reading along.
------------------------------------------------------------------------
[2023-06-21 09:28:10] nguyenthuongzl633 at gmail dot com
In the Linux command line, whether or not a trailing slash is required to identify a directory depends on the specific command or tool you are using.
There are some exceptions where a trailing slash may be required or preferred.
cp -r /path/to/source/directory/ /path/to/destination/
If you omit the trailing slash after the source directory, the cp command will create a new directory inside the destination with the same name as the source directory and copy the contents into that new directory.
Regarding your question about splitting the path and filename in your own functions, if you are using PHP, the pathinfo() function can be helpful. It returns an associative array containing information about a file path, including the directory name and filename. Here's an example:
$path = '/path/to/directory/filename.txt';
$pathInfo = pathinfo($path);
$directory = $pathInfo['dirname']; // Contains '/path/to/directory'
$filename = $pathInfo['filename']; // Contains 'filename'
Regarding PHP 7.4.3, it seems that you are referring to the PHP version installed on your system. The version you mentioned, 7.4.3, is a specific release of PHP that was built on October 6, 2020. If you are unable to select PHP 7.4.3 from the options dropdown, it could indicate that the specific version is not available in the environment you are using. You may need to select an alternative PHP version that is supported in your current setup. (https://www.myaarpmedicares.us/)github.com
I recommend referring to the documentation or contacting the provider of the environment or platform you are using for further assistance in selecting the appropriate PHP version. They should be able to provide you with the available PHP options and help you choose the desired version.
------------------------------------------------------------------------
[2021-05-25 12:13:14] [email protected]
Well, that behavior might be confusing, but it is long
standing[1], and consistent with basedir() and dirname(), so it
can't be changed. A note in the docs won't hurt.
[1] <https://3v4l.org/aXYbl>
[2] <https://3v4l.org/mlkXI>
------------------------------------------------------------------------
[2021-05-24 14:57:13] info at kgsw dot de
Description:
------------
using linux command line, sometimes trailing slash will make sure to identify a directory;
my own, manual functions would first split path from filename at the _last_ slash;
which would find NO filename, only path, in that example;
for me unexpected - so need documentation or is a bug?
I could not find PHP 7.4.3 in the options dropbox to select using:
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
once reported on Win2k - but discarded as "no URL function" - but I think, this is not the point - it is just unexpected
https://bugs.php.net/bug.php?id=41834
If you still insist on that IMHO strange behaviour, I would like to add a note to the manual
Test script:
---------------
php > var_dump( pathinfo('/home/user/backup.2021-05-24/'));
array(4) {
["dirname"]=>
string(10) "/home/user"
["basename"]=>
string(17) "backup.2021-05-24"
["extension"]=>
string(10) "2021-05-24"
["filename"]=>
string(6) "backup"
}
Expected result:
----------------
array(4) {
["dirname"]=>
string(10) "/home/user/backup.2021-05-24"
// no more set - cause no filename given
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81079&edit=1