|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-01-20 20:27 UTC] phpnet at cuntbubble dot com
Hi,
print_r(pathinfo("/foo/bar.bar/baz"));
Array (
[dirname] => /foo/bar.bar
[basename] => baz
[extension] => bar/baz
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 13 08:00:02 2025 UTC |
Reopening. It does appear that pathinfo() reacts badly if: a) the filename portion does not have an extension, AND b) one of the directories has a dot in its name. This is because if the above conditions are met, the extension bit in string.c looks for the last occurrence of '.' in the pathname and takes anything after it as the file's extension. The following patch fixes the problem, if someone with enough karma would like to check it out and check it in (yuk yuk). Torben Index: string.c =================================================================== RCS file: /repository/php4/ext/standard/string.c,v retrieving revision 1.261 diff -u -r1.261 string.c --- string.c 5 Jan 2002 23:49:57 -0000 1.261 +++ string.c 21 Jan 2002 07:48:41 -0000 @@ -1201,11 +1201,18 @@ } if (argc < 2 || opt == PHP_PATHINFO_EXTENSION) { - char *p; + char *p, *last_separator; int idx; p = strrchr(Z_STRVAL_PP(path), '.'); - if (p) { + +#ifdef PHP_WIN32 + last_separator = strrchr(Z_STRVAL_PP(path), '\\'); +#else + last_separator = strrchr(Z_STRVAL_PP(path), '/'); +#endif + + if (p && p > last_separator) { idx = p - Z_STRVAL_PP(path); add_assoc_stringl(tmp, "extension", Z_STRVAL_PP(path) + idx + 1, len - idx - 1, 1); }