jarvis Posted July 7, 2011 Share Posted July 7, 2011 Hi, I've the following URL http://www.domain.com/category/projects/airports How can I get projects from the URL? I had something like: $ref = $_SERVER["REQUEST_URI"]; $array = explode("/", $ref, 2); echo $array[2]; Sadly it didn't work Anyone able to point me in the right direction? TIA Link to comment https://forums.phpfreaks.com/topic/241348-get-part-of-a-domain/ Share on other sites More sharing options...
cssfreakie Posted July 7, 2011 Share Posted July 7, 2011 this maybe? $ref = 'http://www.domain.com/category/projects/airports'; $array = explode("/", $ref); echo $array[4]; Link to comment https://forums.phpfreaks.com/topic/241348-get-part-of-a-domain/#findComment-1239724 Share on other sites More sharing options...
jarvis Posted July 7, 2011 Author Share Posted July 7, 2011 Thanks cssfreakie, that put me in the right direction, I needed this: $array = explode("/", $ref); echo $array[6]; Thanks :-) Link to comment https://forums.phpfreaks.com/topic/241348-get-part-of-a-domain/#findComment-1239727 Share on other sites More sharing options...
Pikachu2000 Posted July 7, 2011 Share Posted July 7, 2011 What you're asking makes no sense, at least not the way you're asking it. What problem are you trying to solve with this code? Link to comment https://forums.phpfreaks.com/topic/241348-get-part-of-a-domain/#findComment-1239729 Share on other sites More sharing options...
jarvis Posted July 7, 2011 Author Share Posted July 7, 2011 Thanks Pikachu2000 but I don't know how else to explain it. I have this domain: http://www.domain.com/category/projects/airports I need to get the projects part of the domain from it. As this may change to something else, like: http://www.domain.com/category/location/usa So I can then use the code to get locations. Depending on whether it's location or projects, depends on what I then show on screen. Does that help? Thanks Link to comment https://forums.phpfreaks.com/topic/241348-get-part-of-a-domain/#findComment-1239731 Share on other sites More sharing options...
AbraCadaver Posted July 7, 2011 Share Posted July 7, 2011 echo basename(dirname($ref)); Link to comment https://forums.phpfreaks.com/topic/241348-get-part-of-a-domain/#findComment-1239743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.