arg

Definition

arg($index)
includes/bootstrap.inc, line 527

Description

Return a component of the current Drupal path.

When viewing a page at the path "admin/node/configure", for example, arg(0) would return "admin", arg(1) would return "node", and arg(2) would return "configure".

Avoid use of this function where possible, as resulting code is hard to read. Instead, attempt to use named arguments in menu callback functions. See the explanation in menu.inc for how to construct callbacks that take arguments.

Code

<?php
function arg($index) {
  static $arguments, $q;

  if (empty($arguments) || $q != $_GET['q']) {
    $arguments = explode('/', $_GET['q']);
  }

  if (array_key_exists($index, $arguments)) {
    return $arguments[$index];
  }
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.