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 242 views
5 answers 441 views
1 answer 104 views
104 views asked Aug 7, 2023 by avibootz
1 answer 169 views
1 answer 233 views
2 answers 268 views
1 answer 240 views
...