arg

Versions
5
arg($index)
6 – 7
arg($index = NULL, $path = NULL)

Return a component of the current Drupal path.

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

Avoid use of this function where possible, as resulting code is hard to read. In menu callback functions, attempt to use named arguments. See the explanation in menu.inc for how to construct callbacks that take arguments. When attempting to use this function to load an element from the current path, e.g. loading the node on a node page, please use menu_get_object() instead.

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.

▾ 54 functions call arg()

aggregator_form_category_submit in core/modules/aggregator/aggregator.admin.inc
Process aggregator_form_category form submissions.
aggregator_form_feed_submit in core/modules/aggregator/aggregator.admin.inc
Process aggregator_form_feed() form submissions.
aggregator_page_category in core/modules/aggregator/aggregator.pages.inc
Menu callback; displays all the items aggregated in a particular category.
aggregator_page_last in core/modules/aggregator/aggregator.pages.inc
Menu callback; displays the most recent items gathered from any feed.
aggregator_page_rss in core/modules/aggregator/aggregator.pages.inc
Menu callback; generate an RSS 0.92 feed of aggregator items or categories.
aggregator_page_source in core/modules/aggregator/aggregator.pages.inc
Menu callback; displays all the items captured from a particular feed.
backup_migrate_crud_ui_create in contrib/backup_migrate/includes/crud.inc
Page callback to create a new item.
backup_migrate_crud_ui_delete in contrib/backup_migrate/includes/crud.inc
Page callback to delete an item.
backup_migrate_crud_ui_edit in contrib/backup_migrate/includes/crud.inc
Page callback to edit an item.
backup_migrate_crud_ui_export in contrib/backup_migrate/includes/crud.inc
Export an item.
backup_migrate_crud_ui_list in contrib/backup_migrate/includes/crud.inc
Page callback to list all items.
backup_migrate_ui_manual_backup_advanced in contrib/backup_migrate/backup_migrate.module
The menu callback for advanced manual backups.
block_admin_display_form in core/modules/block/block.admin.inc
Generate main blocks administration form.
block_block_info_alter in core/modules/block/block.module
Implements hook_block_info_alter().
blog_node_view in core/modules/blog/blog.module
Implements hook_node_view().
comment_admin in core/modules/comment/comment.admin.inc
Menu callback; present an administrative comment listing.
contemplate_edit_type in contrib/contemplate/contemplate.module
dblog_init in core/modules/dblog/dblog.module
Implements hook_init().
devel_node_access_block in core/sites/all/modules/devel/devel_node_access.module
devel_node_access_block_view in contrib/devel/devel_node_access.module
filter_tips_long in core/modules/filter/filter.pages.inc
Menu callback; show a page with long filter tips.
forum_form_alter in core/modules/forum/forum.module
Implements hook_form_alter().
gmap_location_block in contrib/gmap/gmap_location.module
Draw block of location for current node.
gmap_location_user_point in contrib/gmap/gmap_location.module
AHAH callback for getting the contents of a user point popup.
googleanalytics_footer in core/sites/all/modules/google_analytics/googleanalytics.module
Implementation of hook_footer() to insert Javascript at the end of the page.
googleanalytics_page_alter in contrib/google_analytics/googleanalytics.module
Implementation of hook_page_alter() to insert Javascript at the bottom of the page.
hook_overlay_child_initialize in core/modules/overlay/overlay.api.php
Allow modules to act when an overlay child window is initialized.
logintoboggan_form_user_pass_reset_alter in contrib/logintoboggan/logintoboggan.module
Implement hook_form_user_pass_reset_alter().
menu_get_active_help in core/includes/menu.inc
Returns the help associated with the active menu item.
menu_get_item in core/includes/menu.inc
Get a router item.
menu_set_active_trail in core/includes/menu.inc
Sets or gets the active trail (path to root menu root) of the current page.
og_ui_user_admin_role in contrib/og/og_ui/og_ui.admin.inc
Menu callback: administer roles. See alsoog_user_admin_role_validate()
openid_test_yadis_xrds in core/modules/openid/tests/openid_test.module
Menu callback; XRDS document that references the OP Endpoint URL.
openid_user_add_submit in core/modules/openid/openid.pages.inc
page_title_get_title in contrib/page_title/page_title.module
Simple wrapper function to get the currently set title for a page
page_title_page_get_title in contrib/page_title/page_title.module
Determines what title should be sent to the page template.
profile_block_view in core/modules/profile/profile.module
Implements hook_block_view().
profile_field_form in core/modules/profile/profile.admin.inc
Menu callback: Generate a form to add/edit a user profile field. See alsoprofile_field_form_validate()
statistics_exit in core/modules/statistics/statistics.module
Implements hook_exit().
statistics_node_tracker in core/modules/statistics/statistics.pages.inc
statistics_user_tracker in core/modules/statistics/statistics.pages.inc
system_init in core/modules/system/system.module
Implements hook_init().
template_preprocess_html in core/includes/theme.inc
Preprocess variables for html.tpl.php See alsosystem_elements()
template_preprocess_page in core/includes/theme.inc
Preprocess variables for page.tpl.php
template_preprocess_profile_wrapper in core/modules/profile/profile.module
Process variables for profile-wrapper.tpl.php.
update_help in core/modules/update/update.module
Implements hook_help().
user_admin_role in core/modules/user/user.admin.inc
Menu callback: administer roles. See alsouser_admin_role_validate()
user_block_view in core/modules/user/user.module
Implements hook_block_view().
user_reference_user_load in core/sites/all/modules/cck/modules/user_reference/user_reference.module
Implementation of hook_user_load().
xmlsitemap_help in contrib/xmlsitemap/xmlsitemap.module
Implements hook_help().
zen_breadcrumb in contrib/zen/template.php
Return a themed breadcrumb trail.
zen_preprocess_html in contrib/zen/template.php
Override or insert variables into the html template.
_trigger_normalize_user_context in core/modules/trigger/trigger.module
Loads associated objects for user triggers.
_zen_theme in contrib/zen/zen-internals/template.theme-registry.inc
Implements HOOK_theme().

Code

core/includes/path.inc, line 258

<?php
function arg($index = NULL, $path = NULL) {
  // Even though $arguments doesn't need to be resettable for any functional
  // reasons (the result of explode() does not depend on any run-time
  // information), it should be resettable anyway in case a module needs to
  // free up the memory used by it.
  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['arguments'] = &drupal_static(__FUNCTION__);
  }
  $arguments = &$drupal_static_fast['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];
  }
}
?>