note 88654 added to function.pathinfo
| From: | aalaap at gmail dot com | Date: | Mon, 02 Feb 2009 15:58:29 +0000 |
| Subject: | note 88654 added to function.pathinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150102@lists.php.net to get a copy of this message | ||
Here is a simple function that gets the extension of a file. Simply using PATHINFO_EXTENSION will
yield incorrect results if the path contains a query string with dots in the parameter names (for
eg. &x.1=2&y.1=5), so this function eliminates the query string first and subsequently runs
PATHINFO_EXTENSION on the clean path/url.
function extension($path) {
$qpos = strpos($path, "?");
if ($qpos!==false) $path = substr($path, 0, $qpos);
$extension = pathinfo($path, PATHINFO_EXTENSION);
return $extension;
}
Any room for improvement?
----
Server IP: 59.162.86.33
Probable Submitter: 60.254.53.224
----
Manual Page -- http://www.php.net/manual/en/function.pathinfo.php
Edit -- https://master.php.net/note/edit/88654
Del: integrated -- https://master.php.net/note/delete/88654/integrated
Del: useless -- https://master.php.net/note/delete/88654/useless
Del: bad code -- https://master.php.net/note/delete/88654/bad+code
Del: spam -- https://master.php.net/note/delete/88654/spam
Del: non-english -- https://master.php.net/note/delete/88654/non-english
Del: in docs -- https://master.php.net/note/delete/88654/in+docs
Del: other reasons-- https://master.php.net/note/delete/88654
Reject -- https://master.php.net/note/reject/88654
Search -- https://master.php.net/manage/user-notes.php