PHP - Nom de base de la fonction ()

La fonction basename () peut renvoyer le composant de nom de fin de chemin.

Syntaxe

string basename ( string path [, string suffix] )

Il a donné une chaîne contenant un chemin vers un fichier, et cette fonction renvoie le nom de base d'un fichier. Si le nom de fichier se termine par le suffixe, celui-ci peut également être coupé.

Exemple

<?php

   $path = "/PhpProject/index.php";
   $file = basename($path);  //  $file is set to "index.php"
   echo $file . "\n";
   
   $file = basename($path, ".php");  // $file is set to "index"
   echo $file;

?>

Production

index.php
index