Php basename

From CoderLearner
Jump to: navigation, search

PHP function basename

This function returns the file from a path.

Syntax basename

  • path: specifies path to check
  • suffix (option): file extension. If the file has this extension, do not include the extension when return.
basename(path, suffix);

Example 1

<?php
$fileimage = "/home/sophal/image/group.jpg";
echo basename($fileimage); // group.jpg

?>

Output

group.jpg

Example 2

<?php
$fileimage = "/home/sophal/image/group.jpg";
echo basename($fileimage,".jpg"); // group.jpg

?>

Output

group