You are here

function _biblio_extract_surname_parts in Bibliography Module 6.2

Splits a surname string into its prefix and surname parts.

A surname may have a title portion, such as 'den', 'von', 'de la', which are characterised by a lowercased first character. Any uppercased part means lowercased parts following are part of the surname (e.g. Van den Bussche).

Parameters

$input: A string representing a name with a possible prefix.

Return value

array An array with two elements representing surname and name prefix.

2 calls to _biblio_extract_surname_parts()
BiblioContributorUnitTest::testGrabSurname in tests/contributor.test
biblio_parse_author in includes/biblio.contributors.inc
Parses an author name into its component parts.

File

includes/biblio.contributors.inc, line 719
Functions related to contributors in Drupal biblio module.

Code

function _biblio_extract_surname_parts($input) {
  $noPrefix = FALSE;
  $surname = FALSE;
  $prefix = FALSE;
  $surnameArray = explode(" ", $input);
  foreach ($surnameArray as $value) {
    $firstChar = substr($value, 0, 1);
    if (!$noPrefix && ord($firstChar) >= 97 && ord($firstChar) <= 122) {
      $prefix[] = $value;
    }
    else {
      $surname[] = $value;
      $noPrefix = TRUE;
    }
  }
  if (!empty($surname)) {
    $surname = implode(" ", $surname);
  }
  if (!empty($prefix)) {
    $prefix = implode(" ", $prefix);
  }
  return array(
    $surname,
    $prefix,
  );
}