You are here

function _grabFirstnameInitials in Bibliography Module 7

Same name and namespace in other branches
  1. 5 biblio.module \_grabFirstnameInitials()
  2. 6 biblio.contributors.inc \_grabFirstnameInitials()
  3. 7.2 includes/biblio.contributors.inc \_grabFirstnameInitials()

Grab firstname and initials which may be of form "A.B.C." or "A. B. C. " or " A B C " etc.

Parameters

$remainder:

2 calls to _grabFirstnameInitials()
BiblioContributorUnitTest::testGrabFirstnameInitials in tests/BiblioContributorUnitTest.test
biblio_parse_author in includes/biblio.contributors.inc

File

includes/biblio.contributors.inc, line 606

Code

function _grabFirstnameInitials($remainder) {
  $prefix = array();
  $firstname = $initials = '';
  $array = explode(" ", $remainder);
  foreach ($array as $value) {
    $first_char = drupal_substr($value, 0, 1);
    if (ord($first_char) >= 97 && ord($first_char) <= 122) {
      $prefix[] = $value;
    }
    elseif (preg_match("/[a-zA-Z]{2,}/", trim($value))) {
      $firstname_array[] = trim($value);
    }
    else {
      $initials_array[] = trim(str_replace(".", " ", trim($value)));
    }
  }
  if (isset($initials_array)) {
    $initials = implode(" ", $initials_array);
  }
  if (isset($firstname_array)) {
    $firstname = implode(" ", $firstname_array);
  }
  if (!empty($prefix)) {
    $prefix = implode(" ", $prefix);
  }
  return array(
    $firstname,
    $initials,
    $prefix,
  );
}