note 80894 deleted from function.pathinfo by nlopess

From: Date: Thu, 07 Feb 2008 12:16:27 +0000
Subject: note 80894 deleted from function.pathinfo by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-135857@lists.php.net to get a copy of this message
Note Submitter: blodo at poczta dot fm ---- 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] => 飛兒樂團光茫 )

« previous php.notes (#135857) next »