PHP String Exercises: Extract the file name from the specified string
PHP String: Exercise-5 with Solution
Write a PHP script to extract the file name from the following string.
Sample String : 'www.example.com/public_html/index.php'
<?php $path = 'www.example.com/public_html/index.php'; $file_name = substr(strrchr($path, "/"), 1); echo $file_name."\n"; // "index.php" ?>
PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?