So lets say I have a link like this:
http://mywebsite.com/profile/alexkvazos/
I would like to explode the url and get this:
$uri = array('profile','alexkvazos');
What is the easiest approach to this?
So lets say I have a link like this:
http://mywebsite.com/profile/alexkvazos/
I would like to explode the url and get this:
$uri = array('profile','alexkvazos');
What is the easiest approach to this?
try
// if the url is http://www.example.com/foo/bar/wow
function getUriSegments() {
return explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
}
print_r(getUriSegments()); //returns array(0=>'foo', 1=>'bar', 2=>'wow')
Source :- http://www.timwickstrom.com/server-side-code/php/php-get-uri-segments/