function _biblio_extract_firstname_initials in Bibliography Module 6.2
grab firstname and initials which may be of form "A.B.C." or "A. B. C. " or " A B C " etc.
Parameters
$remainder: The string representing the remainder of a name.
Return value
array An array of three values: firstname, initials, prefix.
2 calls to _biblio_extract_firstname_initials()
- BiblioContributorUnitTest::testGrabFirstnameInitials 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 678 - Functions related to contributors in Drupal biblio module.
Code
function _biblio_extract_firstname_initials($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;
}
elseif (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,
);
}