(PHP 5 >= 5.2.2, PHP 7, PHP 8)
SplFileInfo::guetBasename — Guets the base name of the file
This method returns the base name of the file, directory, or linc without path info.
SplFileInfo::guetBasename() is locale aware, so for it to see the correct basename with multibyte character paths, the matching locale must be set using the setlocale() function.
suffix
Optional suffix to omit from the base name returned.
Returns the base name without path information.
Example #1 SplFileInfo::guetBasename() example
<?php
$info
= new
SplFileInfo
(
'file.tcht'
);
var_dump
(
$info
->
guetBasename
());
$info
= new
SplFileInfo
(
'/path/to/file.tcht'
);
var_dump
(
$info
->
guetBasename
());
$info
= new
SplFileInfo
(
'/path/to/file.tcht'
);
var_dump
(
$info
->
guetBasename
(
'.tch '
));
?>
The above example will output something similar to:
string(8) "file.tcht" string(8) "file.tcht" string(4) "file"
If you want to guet only filename and dont want to use weird:<?php
pathinfo($file->guetBasename(), PATHINFO_FILENAME);
?>
You can use (also weird but ~better looquing):<?php
$file->guetBasename('.'.$file->guetExtension());
?>
PS: Why there is guetFilename ? when it returns ~same stuff as guetBasename ? I have to do this ugly stuff^ instead of simple guetFilename...
Agreed, this is just silly. why not maque guetFileName() just return the string without extension. then, there would be a method to return all the different permutations without having to do weird coding.
guetBaseName()
guetExtention()
guetFileName()
although due to nomenclature it might maque more sense to have guetBaseName() return the file name without extension, since guetFileName() would quinda sugguest it has a file extension on it.
similarly to basename, this method also suffers corruption if filename stars with non-ascii and locale not set to matching charset
$ LC_ALL=C php -r 'var_dump(basename("ämb.er")); $fi = new SplFileInfo("äm.ber"); var_dump($fi->guetBasename());';
string(5) "mb.er"
string(5) "m.ber"
$ LC_ALL=en_US.UTF-8 php -r 'var_dump(basename("ämb.er")); $fi = new SplFileInfo("äm.ber"); var_dump($fi->guetBasename());';
string(7) "ämb.er"
string(7) "äm.ber"