note 116754 added to function.pathinfo
| From: | bart at mediawave dot nl | Date: | Mon, 23 Feb 2015 12:55:22 +0000 |
| Subject: | note 116754 added to function.pathinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201791@lists.php.net to get a copy of this message | ||
PHP equivalent for custom implementations. Will be nearly as fast or faster (with long paths):
<?php
$trimPath = rtrim($path, '/');
$slashPos = strrpos($trimPath, '/');
if ($slashPos !== false) {
$dirName = substr($trimPath, 0, $slashPos) ?: '/';
$baseName = substr($trimPath, $slashPos + 1);
} else {
$dirName = '.';
$baseName = $trimPath;
}
$dotPos = strrpos($baseName, '.');
if ($dotPos !== false) {
$fileName = substr($baseName, 0, $dotPos);
$extension = substr($baseName, $dotPos + 1);
} else {
$extension = '';
$fileName = $baseName;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 83.86.2.98
----
Manual Page -- http://php.net/manual/en/function.pathinfo.php
Edit -- https://master.php.net/note/edit/116754
Del: integrated -- https://master.php.net/note/delete/116754/integrated
Del: useless -- https://master.php.net/note/delete/116754/useless
Del: bad code -- https://master.php.net/note/delete/116754/bad+code
Del: spam -- https://master.php.net/note/delete/116754/spam
Del: non-english -- https://master.php.net/note/delete/116754/non-english
Del: in docs -- https://master.php.net/note/delete/116754/in+docs
Del: other reasons-- https://master.php.net/note/delete/116754
Reject -- https://master.php.net/note/reject/116754
Search -- https://master.php.net/manage/user-notes.php