w3resource
php Programming Exercies

PHP String Exercises: Get the filename component of the specified path

PHP String: Exercise-13 with Solution

Write a PHP script to get the filename component of the following path.

Sample path : "https://www.w3resource.com/index.php"

Pictorial Presentation:

PHP String Exercises: Get the filename component of the specified path

Sample Solution:

PHP Code:

<?php
$path = 'www.example.com/public_html/index.php';
$file = basename($path, ".php"); 
echo $file."\n";
?>

Sample Output:

index

Flowchart :

Flowchart: Get the filename component of the specified path

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to put a string in an array.
Next: Write a PHP script to print the next character of a specific character.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming