note 80894 added to function.pathinfo

From: Date: Tue, 05 Feb 2008 22:25:27 +0000
Subject: note 80894 added to function.pathinfo
Groups: php.notes 
Request: Send a blank email to php-notes+get-135805@lists.php.net to get a copy of this message
Here's a custom pathinfo() for dealing with utf8 filenames. <?php function BR_pathinfo ($path, $options=15) { preg_match('#^(.*)[\\/]+([^\\/]+(?:\.[^\\/]+)?)?$#su', $path, $els); $out = array(); if ($options & PATHINFO_DIRNAME) { // 1 $out['dirname'] = $els[1]; } if (isset($els[2])) { if ($options & PATHINFO_BASENAME) { // 2 $out['basename'] = $els[2]; } if ($options & PATHINFO_EXTENSION) { // 4 $out['extension'] = substr($els[2], strrpos($els[2], '.') + 1); } if ($options & PATHINFO_FILENAME) { // 8 $out['filename'] = substr($els[2], 0, strlen($els[2]) - strlen($out['extension']) - 1); } } if (count($out) > 1) { return $out; } else { return end($out); } } print_r(BR_pathinfo('somepath/to/somewhere/飛兒樂團光茫.jpg')); ?> Shows: Array ( [dirname] => http://original-war.net/lo2l [basename] => 飛兒樂團光茫.jpg [extension] => jpg [filename] => 飛兒樂團光茫 ) ---- Server IP: 194.145.210.3 Probable Submitter: 86.1.197.133 ---- Manual Page -- http://www.php.net/manual/en/function.pathinfo.php Edit -- https://master.php.net/note/edit/80894 Del: integrated -- https://master.php.net/note/delete/80894/integrated Del: useless -- https://master.php.net/note/delete/80894/useless Del: bad code -- https://master.php.net/note/delete/80894/bad+code Del: spam -- https://master.php.net/note/delete/80894/spam Del: non-english -- https://master.php.net/note/delete/80894/non-english Del: in docs -- https://master.php.net/note/delete/80894/in+docs Del: other reasons-- https://master.php.net/note/delete/80894 Reject -- https://master.php.net/note/reject/80894 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135805) next »