php - How to fetch id from url? -


i want fetch id url.

url:- localhost/projects/portalgrocery/development/admin/projects/home/edit/27

i have tried:-

    $update_url = $_server['request_uri'];     $path = parse_url($update_url, php_url_path);     $pathcomponents = explode("/", trim($path, "/"));     $id = $pathcomponents[7]; 

it working fine when upload project on live site, have change component number everytime , in every controller there difference in no. of components.

so, want know if there other method fetch so..?

$id = substr(strrchr($_server['request_uri'], '/'), 1); 

this code extracts part of string after last /


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -