You are here

public static function BiblioContributorUtility::getLastname in Bibliography Module 7.3

Get last name and last name prefix from a given string.

Parameters

$value: String containing last name and last name prefix.

Return value

Array with two separated strings: last name and last name prefix.

1 call to BiblioContributorUtility::getLastname()
BiblioContributorUtility::parseContributorName in includes/BiblioContributorUtility.inc
Get each part of a contributor's name separately.

File

includes/BiblioContributorUtility.inc, line 184
Helper class for handling Biblio Contributors.

Class

BiblioContributorUtility
@file Helper class for handling Biblio Contributors.

Code

public static function getLastname($value) {
  $prefix = array();
  $lastname = array();

  // Split the given string to its parts.
  $parts = explode(' ', $value);
  foreach ($parts as $part) {
    if (empty($lastname) && ord(substr($part, 0, 1)) >= 97 && ord(substr($part, 0, 1)) <= 122) {

      // The part starts with a lowercase letter and comes before any last names
      // were found so this is a prefix such as 'den', 'von', 'de la' etc.
      $prefix[] = $part;
      continue;
    }

    // The part starts with an uppercase letter and/or comes after a last name
    // was found in the given string so this is a last name such as 'Bush'.
    $lastname[] = $part;
  }

  // Convert arrays to strings.
  $prefix = !empty($prefix) ? implode(' ', $prefix) : '';
  $lastname = !empty($lastname) ? implode(' ', $lastname) : '';
  return array(
    $lastname,
    $prefix,
  );
}