function arg

7.x bootstrap.inc arg($index = NULL, $path = NULL)
6.x path.inc arg($index = NULL, $path = NULL)

Return a component of the current Drupal path.

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

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.

Parameters

$index: The index of the component, where each component is separated by a '/' (forward-slash), and where the first component has an index of 0 (zero).

$path: A path to break into components. Defaults to the path of the current page.

Return value

The component specified by $index, or NULL if the specified component was not found. If called without arguments, it returns an array containing all the components of the current path.

34 calls to arg()
aggregator_form_category_submit in drupal-6.x/modules/aggregator/aggregator.admin.inc
Process aggregator_form_category form submissions.
aggregator_form_feed_submit in drupal-6.x/modules/aggregator/aggregator.admin.inc
Process aggregator_form_feed form submissions.
aggregator_page_category in drupal-6.x/modules/aggregator/aggregator.pages.inc
Menu callback; displays all the items aggregated in a particular category.
aggregator_page_last in drupal-6.x/modules/aggregator/aggregator.pages.inc
Menu callback; displays the most recent items gathered from any feed.
aggregator_page_rss in drupal-6.x/modules/aggregator/aggregator.pages.inc
Menu callback; generate an RSS 0.92 feed of aggregator items or categories.

... See full list

File

drupal-6.x/includes/path.inc, line 162
Functions to handle paths in Drupal, including path aliasing.

Code

function arg($index = NULL, $path = NULL) {
  static $arguments;

  if (!isset($path)) {
    $path = $_GET['q'];
  }
  if (!isset($arguments[$path])) {
    $arguments[$path] = explode('/', $path);
  }
  if (!isset($index)) {
    return $arguments[$path];
  }
  if (isset($arguments[$path][$index])) {
    return $arguments[$path][$index];
  }
}