note 108327 deleted from function.pathinfo by danbrown

From: Date: Thu, 10 May 2012 17:09:20 +0000
Subject: note 108327 deleted from function.pathinfo by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187659@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- ////////////////////////////////////////////////////// // // http://xszhuchao.blogbus.com/logs/130081187.html // 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 繁體中文 // My Blog // http://samwphp.blogspot.com/2012/04/pathinfo-function.html ////////////////////////////////////////////////////// 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 }}} ///////////////////////////////

« previous php.notes (#187659) next »