w3resource
php Programming Exercies

PHP String Exercises: Get the characters after the last '/' in an url

PHP String: Exercise-22 with Solution

Write a PHP script to get the characters after the last '/' in an url.

Sample URL : 'http://www.example.com/5478631'

Pictorial Presentation:

PHP String Exercises: Get the characters after the last '/' in an url

Sample Solution:

PHP Code:

<?php
$my_url = 'http://www.example.com/5478631';
echo substr($my_url, strrpos($my_url, '/' )+1)."\n";
?>

Sample Output:

5478631

Flowchart :

Flowchart: Get the characters after the last '/' in an url

PHP Code Editor:

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

Previous: Write a PHP script to remove trailing slash from a string.
Next: Write a PHP script to replace multiple characters from the following string.

What is the difficulty level of this exercise?



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