I’m trying to get values from a url using php. With basename I only get the last part but i need the part before that as well.
This is the domain: http://mydomain.nl/first/second/third/
$url = parse_url($entry['source_url']);
$urlFragments = explode('/', $url);
$second = $urlFragments[0];
$third = $urlFragments[1];
I need to use part second and part third.
3
Answers
This script can help you
First of all, to make it simple I remove
http://
part and then explode it with/
and get a different part of the data which is separated by/
@idka-80 try this,
As you can tell from the fatal error, you’re making a wrong assumption about how parse_url() works:
If you only want a specific fragment, you need to tell which one:
You also possibly want to discard leading and trailing slashes: