# How to get file name from a path in PHP?

PHPServer Side ProgrammingProgramming

To get the file name from a path, the code is as follows−

## Example

Live Demo

<?php
$file = pathinfo('/home/cg/root/6985034/main.php'); echo$file['basename'], "\n";
?>

## Output

This will produce the following output−

main.php

## Example

Let us now see another example −

Live Demo

<?php
$path = "/home/cg/root/6985034/main.php";$file = basename($path, ".php"); echo$file;
?>

## Output

This will produce the following output−

main
Published on 27-Dec-2019 07:36:26