I am working with the PHP explode function. This function is used to detect page URL.
In our website settings, the page URLs are:
- /app/home/ (Home page)
- /app/answers/list (Search list page)
- /app/answers/detail/a_id/309 (Answer detail page)
- /app/answers/list/session/L3NpZC9WVmpBQWlxaw%3D%3D
Currently, I am using the explode function to split up the strings and store them in an array.
$currentLocation =explode("/",$_SERVER["REQUEST_URI"]);
Array ( [0] => [1] => app [2] => answers [3] => list [4] => session [5] => L3NpZC9WVmpBQWlxaw%3D%3D )
And then there are a lot of IF Else condition statement:
if ($currentLocation [2]=='home')
{
$this->data['pageURL']=$currentLocation [2]; //Home directory
}
else if($currentLocation [2]=='answers')
{
$this->data['pageURL']= $currentLocation [4];
}
I am wondering whether there is a smart way to achieve this. Thank you. the /app/ part of URL is always fixed, the rest will change.
Cheers, Qing