Get Last Part of URL PHP

The Solution to Get Last Part of URL PHP is


The absolute simplest way to accomplish this, is with basename()

echo basename('http://domain.com/artist/song/music-videos/song-title/9393903');

Which will print

9393903

Of course, if there is a query string at the end it will be included in the returned value, in which case the accepted answer is a better solution.

~ Answered on 2012-01-04 08:47:37


Most Viewed Questions: