Views Contextual filter: php code for getting the value from url Im trying to set up a Contextual filter in drupal views based on the URL. 

The contextual filter is operating with a text field that sets the node alias.

I have it working with "RAW value from URL" based on the position (parentpage/childpage/grandchild-page), but the position could change (only parents and child for example), so do i need to use the "PHP code", or is there a better way?

What i want to happen:

"If last section of page url, (grandchild-page), matches field set in contextual filter, then true (show fields).
Though the solution you have implemented worked but my suggestion is to use the request_uri() instead of the $_SERVER['REQUEST_URI'] because of the following reasons:


$_SERVER['REQUEST_URI'] is only available on Apache, whereas request_uri() generate an equivalent using other environment variables.
Apache does nothing by default to sanitize the $_SERVER variables so directly using it without passing through the check_plain should be considered unsafe.


So its better to get the URL like this:


  $current_url = check_plain(request_uri());


Example: if the url is http://www.example.com/param1/param2/param3 than the $current_url will contain /param1/param2/param3. 

Rest you can build the logic to get the last params, there are numerous ways of doing that.