You are here

function biblio_explode_keywords in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 includes/biblio.keywords.inc \biblio_explode_keywords()
  2. 7 includes/biblio.keywords.inc \biblio_explode_keywords()
  3. 7.2 includes/biblio.keywords.inc \biblio_explode_keywords()
3 calls to biblio_explode_keywords()
biblio_form_validate in ./biblio.module
Implementation of hook_validate().
biblio_insert_keywords in ./biblio.keywords.inc
_biblio_keyword_links in ./biblio.pages.inc

File

./biblio.keywords.inc, line 263

Code

function biblio_explode_keywords($string, $sep = NULL) {
  if (!$sep) {
    $sep = check_plain(variable_get('biblio_keyword_sep', ','));
  }
  $regexp = '%(?:^|' . $sep . '\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^"' . $sep . ']*))%x';
  preg_match_all($regexp, $string, $matches);
  $keyword_array = array_unique($matches[1]);
  $keywords = array();
  foreach ($keyword_array as $keyword) {

    // If a user has escaped a term (to demonstrate that it is a group,
    // or includes a comma or quote character), we remove the escape
    // formatting so to save the term into the database as the user intends.
    $keyword = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $keyword)));
    if ($keyword != "") {
      $keywords[] = $keyword;
    }
  }
  return $keywords;
}