You are here

function biblio_explode_keywords in Bibliography Module 7.2

Same name and namespace in other branches
  1. 6.2 includes/biblio.keywords.inc \biblio_explode_keywords()
  2. 6 biblio.keywords.inc \biblio_explode_keywords()
  3. 7 includes/biblio.keywords.inc \biblio_explode_keywords()
4 calls to biblio_explode_keywords()
BiblioKeywordUnitTest::testBiblioExplodeKeywords in tests/keyword.test
biblio_insert_keywords in includes/biblio.keywords.inc
Insert keywords into the database
biblio_node_form_validate in ./biblio.module
Implements hook_validate().
_biblio_keyword_links in includes/biblio.theme.inc

File

includes/biblio.keywords.inc, line 331

Code

function biblio_explode_keywords($string) {
  $sep = 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;
}