- MFH Pathinfo allows to get filename (Toby S, Christian S)

This commit is contained in:
Marcus Boerger 2006-07-16 10:37:24 +00:00
parent 9c30e20bd6
commit f03f2c5eae
3 changed files with 27 additions and 1 deletions

2
NEWS
View file

@ -56,6 +56,8 @@ PHP NEWS
. Added readInnerXML(), readOuterXML(), readString(), setSchema(). (2.6.20+) . Added readInnerXML(), readOuterXML(), readString(), setSchema(). (2.6.20+)
. Changed to passing libxml options when loading reader. . Changed to passing libxml options when loading reader.
- Added PATHINFO_FILENAME option to pathinfo() to get the filename. (Toby S.,
Christian S.)
- Added array_fill_keys(). (Marcus, Matthew Wilmas) - Added array_fill_keys(). (Marcus, Matthew Wilmas)
- Added posix_initgroups() function. (Ilia) - Added posix_initgroups() function. (Ilia)
- Added an optional parameter to parse_url() to allow retrieval of distinct URL - Added an optional parameter to parse_url() to allow retrieval of distinct URL

View file

@ -59,7 +59,8 @@
#define PHP_PATHINFO_DIRNAME 1 #define PHP_PATHINFO_DIRNAME 1
#define PHP_PATHINFO_BASENAME 2 #define PHP_PATHINFO_BASENAME 2
#define PHP_PATHINFO_EXTENSION 4 #define PHP_PATHINFO_EXTENSION 4
#define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION) #define PHP_PATHINFO_FILENAME 8
#define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION | PHP_PATHINFO_FILENAME)
#define STR_STRSPN 0 #define STR_STRSPN 0
#define STR_STRCSPN 1 #define STR_STRCSPN 1
@ -74,6 +75,7 @@ void register_string_constants(INIT_FUNC_ARGS)
REGISTER_LONG_CONSTANT("PATHINFO_DIRNAME", PHP_PATHINFO_DIRNAME, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PATHINFO_DIRNAME", PHP_PATHINFO_DIRNAME, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PATHINFO_BASENAME", PHP_PATHINFO_BASENAME, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PATHINFO_BASENAME", PHP_PATHINFO_BASENAME, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PATHINFO_EXTENSION", PHP_PATHINFO_EXTENSION, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PATHINFO_EXTENSION", PHP_PATHINFO_EXTENSION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PATHINFO_FILENAME", PHP_PATHINFO_FILENAME, CONST_CS | CONST_PERSISTENT);
#ifdef HAVE_LOCALECONV #ifdef HAVE_LOCALECONV
/* If last members of struct lconv equal CHAR_MAX, no grouping is done */ /* If last members of struct lconv equal CHAR_MAX, no grouping is done */
@ -1385,6 +1387,26 @@ PHP_FUNCTION(pathinfo)
efree(ret); efree(ret);
} }
} }
if ((opt & PHP_PATHINFO_FILENAME) == PHP_PATHINFO_FILENAME) {
char *p;
int idx;
int have_basename = ((opt & PHP_PATHINFO_BASENAME) == PHP_PATHINFO_BASENAME);
/* Have we alrady looked up the basename? */
if (!have_basename) {
php_basename(path, path_len, NULL, 0, &ret, &ret_len TSRMLS_CC);
}
p = strrchr(ret, '.');
idx = p ? (p - ret) : ret_len;
add_assoc_stringl(tmp, "filename", ret, idx, 1);
if (!have_basename) {
efree(ret);
}
}
if (opt == PHP_PATHINFO_ALL) { if (opt == PHP_PATHINFO_ALL) {
RETURN_ZVAL(tmp, 0, 1); RETURN_ZVAL(tmp, 0, 1);

View file

@ -14,4 +14,6 @@ array(3) {
string(8) "dsds.asa" string(8) "dsds.asa"
["extension"]=> ["extension"]=>
string(3) "asa" string(3) "asa"
["filename"]=>
string(4) "dsds"
} }