DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Pretty Urls

05.25.2005
| 1939 views |
  • submit to reddit
        If url is 'index.php/hello' then $request will be 'hello'

$request = $_SERVER['PATH_INFO'];
if (isset($request[0]) && ($request[0] == '/')) {
    $request = substr($request, 1);
}
    

Comments

p c replied on Tue, 2007/02/20 - 12:09am

In order to do the 'split' thing: $data = explode("/",$_SERVER['PATH_INFO']); $request = $data[0];

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

Cool! I don't know PHP, but is there a way you could use a 'split' sort of function to do this automatically?