I need to extract the third part of the URL (if it is there). Demo URL: http://www.glitters8.com/graphics/friends/blah..etc.. I need to extract the 3rd part (ie. friends), as long as it exist. What`s the best way to do that?
<?php $url = 'http://www.glitters8.com/graphics/friends/blah'; $parsed_url = parse_url($url); $exploded = explode('/', $parsed_url['path']); print $exploded[2]; ?> Code (markup): It would be easier to get with regex, but I used parse_url since it's faster to write.