note 108774 added to function.pathinfo

From: Date: Wed, 23 May 2012 22:57:18 +0000
Subject: note 108774 added to function.pathinfo
Groups: php.notes 
Request: Send a blank email to php-notes+get-188181@lists.php.net to get a copy of this message
////////////////////////////////////////////////////// // // I Refer above article. // Fix Some Exception. // Make a Function like pathinfo. // This is useful for multi byte characters. // There some example on the bottom。 // I Use 繁體中文 ////////////////////////////////////////////////////// function my_pathinfo($path) { $dirname = ''; $basename = ''; $extension = ''; $filename = ''; $pos = strrpos($path, '/'); if($pos !== false) { $dirname = substr($path, 0, strrpos($path, '/')); $basename = substr($path, strrpos($path, '/') + 1); } else { $basename = $path; } $ext = strrchr($path, '.'); if($ext !== false) { $extension = substr($ext, 1); } $filename = $basename; $pos = strrpos($basename, '.'); if($pos !== false) { $filename = substr($basename, 0, $pos); } return array ( 'dirname' => $dirname, 'basename' => $basename, 'extension' => $extension, 'filename' => $filename ); } /////////////////////////////// // test {{{ $pass = pathinfo('/mnt/files/飛兒樂團光茫.mp3'); var_dump($pass); $pass = my_pathinfo('/mnt/files/飛兒樂團光茫.mp3'); var_dump($pass); $pass = my_pathinfo('飛兒樂團光茫.mp3'); var_dump($pass); $pass = my_pathinfo('/飛兒樂團光茫.mp3'); var_dump($pass); // test }}} /////////////////////////////// /////////////////////////////// // result {{{ /* array(4) { ["dirname"]=> string(10) "/mnt/files" ["basename"]=> string(4) ".mp3" ["extension"]=> string(3) "mp3" ["filename"]=> string(0) "" } array(4) { ["dirname"]=> string(10) "/mnt/files" ["basename"]=> string(22) "飛兒樂團光茫.mp3" ["extension"]=> string(3) "mp3" ["filename"]=> string(18) "飛兒樂團光茫" } array(4) { ["dirname"]=> string(0) "" ["basename"]=> string(22) "飛兒樂團光茫.mp3" ["extension"]=> string(3) "mp3" ["filename"]=> string(18) "飛兒樂團光茫" } array(4) { ["dirname"]=> string(0) "" ["basename"]=> string(22) "飛兒樂團光茫.mp3" ["extension"]=> string(3) "mp3" ["filename"]=> string(18) "飛兒樂團光茫" } */ // result }}} /////////////////////////////// ---- Server IP: 69.147.83.197 Probable Submitter: 125.231.40.138 ---- Manual Page -- http://www.php.net/manual/en/function.pathinfo.php Edit -- https://master.php.net/note/edit/108774 Del: integrated -- https://master.php.net/note/delete/108774/integrated Del: useless -- https://master.php.net/note/delete/108774/useless Del: bad code -- https://master.php.net/note/delete/108774/bad+code Del: spam -- https://master.php.net/note/delete/108774/spam Del: non-english -- https://master.php.net/note/delete/108774/non-english Del: in docs -- https://master.php.net/note/delete/108774/in+docs Del: other reasons-- https://master.php.net/note/delete/108774 Reject -- https://master.php.net/note/reject/108774 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188181) next »