Friday, February 4, 2011

Getting URL Parameter / Arguments Values

Explode Functions is used to get the parameter or arguments from url in drupal

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

where

  • $pieces is the variable where the url is splitted and stored as an array.
  • $_GET['q'] will contain the url address
Points to remember
  • Values will be splited against '/'
  • $pieces[1] will contains the first parameter after splitting
Explode function can also be used to split any normal Variable
  1. for eg. if $abc='India-Wins'
  2. $xyz = explode('-', $abc); // the variable is splitted against '-' (hipen)
  3. now $xyz[0]='India' and $xyz[1]='Wins'

No comments:

Post a Comment