note 118067 added to splfileinfo.getfilename

From: Date: Mon, 28 Sep 2015 15:39:30 +0000
Subject: note 118067 added to splfileinfo.getfilename
Groups: php.notes 
Request: Send a blank email to php-notes+get-203868@lists.php.net to get a copy of this message
I was trying to work out the difference between this and getBasename (http://php.net/manual/splfileinfo.getbasename.php) and the only difference I could really see was a special case of a file in the filesystem root with the root specified: <?php function getInfo($reference) { $file = new SplFileInfo($reference); var_dump($file->getFilename()); var_dump($file->getBasename()); } $test = [ '/path/to/file.txt', '/path/to/file', '/path/to/', 'path/to/file.txt', 'path/to/file', 'file.txt', '/file.txt', '/file', ]; foreach ($test as $file) { getInfo($file); } // will return: /* string(8) "file.txt" string(8) "file.txt" string(4) "file" string(4) "file" string(2) "to" string(2) "to" string(8) "file.txt" string(8) "file.txt" string(4) "file" string(4) "file" string(8) "file.txt" string(8) "file.txt" string(9) "/file.txt" // see how getFilename includes the '/' string(8) "file.txt" // but getBasename doesn't string(5) "/file" // ditto getFilename string(4) "file" // ditto getBasename */ ?> ---- Server IP: 72.52.91.14 Probable Submitter: 89.213.15.97 ---- Manual Page -- http://php.net/manual/en/splfileinfo.getfilename.php Edit -- https://master.php.net/note/edit/118067 Del: integrated -- https://master.php.net/note/delete/118067/integrated Del: useless -- https://master.php.net/note/delete/118067/useless Del: bad code -- https://master.php.net/note/delete/118067/bad+code Del: spam -- https://master.php.net/note/delete/118067/spam Del: non-english -- https://master.php.net/note/delete/118067/non-english Del: in docs -- https://master.php.net/note/delete/118067/in+docs Del: other reasons-- https://master.php.net/note/delete/118067 Reject -- https://master.php.net/note/reject/118067 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203868) next »