note 73226 deleted from function.pathinfo by mazzanet
| From: | mazzanet@php.net | Date: | Wed, 14 Feb 2007 09:21:02 +0000 |
| Subject: | note 73226 deleted from function.pathinfo by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123350@lists.php.net to get a copy of this message | ||
Note Submitter: corySPAM at lavacube dot com
----
Here is my simple alternative to pathinfo using preg_match:
<?php
function path_info( $path )
{
preg_match('/^(.*)\/(.*)(\.(.*))+$/', str_replace('\\', '/',
$path), $matches);
return array( 'dirname' => $matches[1],
'basename' =>
($matches[3]?$matches[2].'.'.$matches[4]:$matches[2]),
'extension' => ($matches[4]?$matches[4]:null),
'filename' => $matches[2] );
}
?>
I'm not the greatest at regular expressions. If I am doing anything wrong, please let me know!
Thanks, and enjoy!