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.
$data['current_uri'] = $this->uri->segment(1); $this->load->view('header', $data); in each of my controllers and then in the header. php file, I check the $current_uri variable to determine which part of the navigation should be highlighted.
$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/'; $uri = substr($_SERVER['REQUEST_URI'], strlen($basepath)); if (strstr($uri, '? ')) $uri = substr($uri, 0, strpos($uri, '? ')); $url = trim($uri, '/');
A more complete Example:
var_dump(parse_url(http://lambo-car-dealer.com/Lambo/All+Models/2018/?limits=10&advance_options=no));
output:
array(4) {
["scheme"]=>
string(4) "http"
["host"]=>
string(48) "lambo-car-dealer.com"
["path"]=>
string(44) "/Lambo/All+Models/2018/"
["query"]=>
string(121) "limits=10&advance_options=no"
}
Also can get it this way:
$URL = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$URI = "$_SERVER[REQUEST_URI]";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With