You are here

function _grabFirstnameInitials in Bibliography Module 6

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

Parameters

$remainder:

Return value

unknown_type

1 call to _grabFirstnameInitials()
biblio_parse_author in ./biblio.contributors.inc

File

./biblio.contributors.inc, line 341

Code

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