I have created a URL/menu item via hook_menu, and in the proprocess_html I'd like to get my item (last element in the URL) (/test) without using arg(0).

I can do it in PHP but I was wondering how it was possible to get this with drupal.

end(explode("/", request_uri()))

this code is actually bad, there could be URL such as ?test=ok


  • Why not using arg() ?
    – pbonnefoi
    Commented Feb 26, 2015 at 15:20
  • let's say that on different branches I have a / more in the url so arg(0) become arg(1)
    – GwenM
    Commented Feb 26, 2015 at 15:53
  • Do you know if your item is going to change ? like is it always going to be "test" ?
    – pbonnefoi
    Commented Feb 26, 2015 at 16:08
  • Yes it will be always the same last argument in the URI http://%/%/%/test
    – GwenM
    Commented Feb 26, 2015 at 16:12
  • 1
    I think arg() only starts where drupal is installed so it should work in your case.
    – pbonnefoi
    Commented Feb 26, 2015 at 16:23

1 Answer 1


will return the last component of the current Drupal path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.