1.2.1337. 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.1337.1. Suggestions

  • Use pathinfo() and its second argument

1.2.1337.2. Specs

Short name

Php/UsePathinfo

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

pathinfo

Examples

SuiteCrm

Available in

Entreprise Edition, Community Edition, Exakat Cloud