You are here

function taxonomy_terms_parse_string in Drupal 5

Same name and namespace in other branches
  1. 6 modules/taxonomy/taxonomy.module \taxonomy_terms_parse_string()

Parses a comma or plus separated string of term IDs.

Parameters

$str_tids: A string of term IDs, separated by plus or comma. comma (,) means AND plus (+) means OR

Return value

an associative array with an operator key (either 'and' or 'or') and a tid key containing an array of the term ids.

1 call to taxonomy_terms_parse_string()
taxonomy_term_page in modules/taxonomy/taxonomy.module
Menu callback; displays all nodes associated with a term.

File

modules/taxonomy/taxonomy.module, line 1376
Enables the organization of content into categories.

Code

function taxonomy_terms_parse_string($str_tids) {
  $terms = array();
  if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_tids)) {
    $terms['operator'] = 'or';

    // The '+' character in a query string may be parsed as ' '.
    $terms['tids'] = preg_split('/[+ ]/', $str_tids);
  }
  else {
    if (preg_match('/^([0-9]+,)*[0-9]+$/', $str_tids)) {
      $terms['operator'] = 'and';
      $terms['tids'] = explode(',', $str_tids);
    }
  }
  return $terms;
}