note 72114 deleted from function.pathinfo by nlopess
| From: | nlopess@php.net | Date: | Thu, 15 Feb 2007 13:06:49 +0000 |
| Subject: | note 72114 deleted from function.pathinfo by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123417@lists.php.net to get a copy of this message | ||
Note Submitter: Microphage71
----
function pathInfos ($path)
{
$tab = pathinfo($path);
$tab['dirname'] = str_replace ('.', './',
$tab['dirname']);
if (strstr (PHP_OS, 'WIN'))
{
$tab['dirname'] = str_replace ('\\', '/',
$tab['dirname']);
}
if ($tab['dirname'] == '')
{
$tab['dirname'] = './';
}
if (substr ($tab['dirname'], strlen ($tab['dirname']) - 1, 1) !=
'/')
{
$tab['dirname'] .= '/';
}
if (strpos ($tab['basename'], '.') !== false)
{
$tab['filename'] = substr ($tab['basename'], 0, strpos
($tab['basename'], '.'));
$tab['extension'] = substr ($tab['basename'], strpos
($tab['basename'], '.') + 1);
}
else
{
$tab['extension'] = '';
}
return $tab;
}
ex 1:
-----
echo print_r (pathInfos ('/a/b/c'));
Array
(
[dirname] => /a/b/
[basename] => c
[filename] => c
[extension] =>
)
ex 2:
-----
echo print_r (pathInfos ('/a/b/c.tar'));
Array
(
[dirname] => /a/b/
[basename] => c.tar
[filename] => c
[extension] => tar
)
ex 3:
-----
echo print_r (pathInfos ('c.tar.gz'));
Array
(
[dirname] => ./
[basename] => c.tar.gz
[filename] => c
[extension] => tar.gz
)