2009-05-04 14:26:54 +00:00

38 lines
865 B
PHP

<?php
/**
* Return a component of the current 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".
*
* @param $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).
*
* @return
* The component specified by $index, or NULL if the specified component was
* not found.
*/
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];
}
}
?>