1.2.1311. Use Basename Suffix¶
basename() is able to remove a file extension when it is provided as argument. The second argument is removed from the name of the file.
Using basename() instead of substr() or else, makes the intention clear.
<?php
$path = 'phar:///path/to/file.php';
// Don't forget the .
$filename = basename($path, '.php');
// Too much work for this
$filename = substr(basename($path), 0, -4);
?>
See also basename.
1.2.1311.1. Suggestions¶
Use basename(), remove more complex code based on substr() or str_replace()
1.2.1311.2. Specs¶
Short name |
Structures/BasenameSuffix |
Rulesets |
|
Exakat since |
1.5.1 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Features |
basename, file-extension, dirname |
Examples |
|
Available in |