I have 2 strings and substitute them, so I get just URI parts.
$base_url = 'http://localhost/project/';
$url = 'http://localhost/project/controller/action/param1/param2';
I am checking for URI parts.
$only_segments = str_replace($base_url, '', $real_url);
Basicly I do: {url} - {base_url} = {only_segments}
Then I can get segments:
$parts = explode('/', $only_segments);
print_r($parts);
Question:
Am I on right path or can it be done easier with $_SERVER['REQUEST_URI'] ?
Note: I don't want project
in URI parts, it is sub-folder of localhost.
Look into
parse_url()
. That will get you most of the way there. All you would need to do is remove the portion of the path that is part of your base URL.A more complete Example:
output:
}
Also can get it this way: