exemple d'un code pour récupérer l'extension d'un fichier que j'ai utilisé asès longtemps :
<?php
function get_file_ext($file)
{
$ext = substr(strtolower(strrchr(basename($file), ".")), 1);
return $ext;
}
?>
function get_file_ext($file)
{
$ext = substr(strtolower(strrchr(basename($file), ".")), 1);
return $ext;
}
?>
Voici maintenant la même chose avec une fonction intégré dans PHP qui fais la même chose en une seul étape : récupérer l'extension d'un fichier
<?php
$ext = pathinfo('le_fichier.html', PATHINFO_EXTENSION);
?>
$ext = pathinfo('le_fichier.html', PATHINFO_EXTENSION);
?>
Plus d'information sur pathinfo
pathinfo a besoin de PHP 4 >= 4.0.3, PHP 5
Aucun commentaire:
Enregistrer un commentaire