Is there a function for returning the parts of an aliased path? I'm looking for something equivalent to the arg() function.

I've been using something like this:

$path_parts = explode('/', drupal_get_path_alias($_GET['q']));

but this would return an empty array if there were just a single part, ie. http://localhost/about

Comments

WorldFallz’s picture

afaik, it should still work.... try this to see:

print_r(explode('/','about'));

You should get:

Array ( [0] => about ) 

Edit: I made my own alias version (aarg) of the drupal api arg function:

<?php
function aarg($index = NULL, $path = NULL) {
  if (!isset($path)) {
    $path = drupal_get_path_alias($_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];
  }
}
?>

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

aspafford’s picture

you're right, that does work. Anyways this function was what I was really going for, thanks!

WorldFallz’s picture

welcome ;-)

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

aterchin’s picture

WorldFallz: Just curious why you didn't include the

static $arguments;

from the arg function

WorldFallz’s picture

Probably just an oversight, though I confess, in this function I'm not sure what its purpose would be.

adrianmak’s picture

subscribe

MKorostoff’s picture

In drupal 7 its just

request_path()