1.2.1346. Use Pathinfo¶
Use pathinfo() function instead of string manipulations.
pathinfo() is more efficient and readable and string functions. When the path contains UTF-8 characters, pathinfo() may strip them. There, string functions are necessary.
<?php
$filename = '/path/to/file.php';
// With pathinfo();
$details = pathinfo($filename);
print $details['extension']; // also capture php
// With string functions (other solutions possible)
$ext = substr($filename, - strpos(strreverse($filename), '.')); // Capture php
?>
1.2.1346.1. Suggestions¶
Use pathinfo() and its second argument
1.2.1346.2. Specs¶
Short name |
Php/UsePathinfo |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |