note 111182 added to function.pathinfo
| From: | Chris | Date: | Wed, 23 Jan 2013 11:52:58 +0000 |
| Subject: | note 111182 added to function.pathinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193359@lists.php.net to get a copy of this message | ||
The function provided by Pietro Baricco works very well. Thank you Pietro.
To be more compatible with pathinfo() it could be changed to something like this:
<?php
function mb_pathinfo( $filepath, $options = null ) {
preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im',$filepath,$m);
if($m[1]) $ret['dirname']=$m[1];
if($m[2]) $ret['basename']=$m[2];
if($m[5]) $ret['extension']=$m[5];
if($m[3]) $ret['filename']=$m[3];
// foo.pdf returns . as dirname
if( $ret['dirname'] == '' ) $ret['dirname'] = '.';
if( $options === null ){
return $ret;
}else{
$map = array(
PATHINFO_DIRNAME => 'dirname',
PATHINFO_BASENAME => 'basename',
PATHINFO_EXTENSION => 'extension',
PATHINFO_FILENAME => 'filename',
);
return $ret[ $map[ $options ] ];
}
}
?>
----
Server IP: 213.172.110.14
Probable Submitter: 212.68.67.242
----
Manual Page -- http://php.net/manual/en/function.pathinfo.php
Edit -- https://master.php.net/note/edit/111182
Del: integrated -- https://master.php.net/note/delete/111182/integrated
Del: useless -- https://master.php.net/note/delete/111182/useless
Del: bad code -- https://master.php.net/note/delete/111182/bad+code
Del: spam -- https://master.php.net/note/delete/111182/spam
Del: non-english -- https://master.php.net/note/delete/111182/non-english
Del: in docs -- https://master.php.net/note/delete/111182/in+docs
Del: other reasons-- https://master.php.net/note/delete/111182
Reject -- https://master.php.net/note/reject/111182
Search -- https://master.php.net/manage/user-notes.php