How to use the function basename() to get the filename from a path in PHP

2 Answers

0 votes
$path = "c:/xampp/htdocs/knowrex.com/index.php";
$file = basename($path);

echo "File name: $file<br />";
   
/*
run:

File name: index.php
 
*/

 



answered Apr 16, 2016 by avibootz
0 votes
$path = "c:/xampp/htdocs/knowrex.com/index.php";

$file = basename($path, ".php");
 
echo "File name: $file<br />";
   
$file = basename($path, ".c");
 
echo "File name: $file<br />";   
   
/*
run:

File name: index
File name: index.php
 
*/

 



answered Apr 16, 2016 by avibootz

Related questions

1 answer 329 views
5 answers 640 views
1 answer 177 views
177 views asked Aug 7, 2023 by avibootz
1 answer 277 views
1 answer 326 views
2 answers 408 views
1 answer 350 views
...