本文整理汇总了PHP中UTF8::utf8_substr方法的典型用法代码示例。如果您正苦于以下问题:PHP UTF8::utf8_substr方法的具体用法?PHP UTF8::utf8_substr怎么用?PHP UTF8::utf8_substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8
的用法示例。
在下文中一共展示了UTF8::utf8_substr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkInitials
/**
* Handle initials.
*
* Taken from OSBib
*
* @see formatNames()
*
* @author Mark Grimshaw
* @version 1
*
* @param $creator Associative array of creator name e.g.
* <pre>
* array(['surname'] => 'Grimshaw', ['firstname'] => Mark, ['initials'] => 'M N G', ['prefix'] => ))
* </pre>
* Initials must be space-delimited.
*
* @param $initialsStyle
* @param $firstNameInitial
* @return Formatted string of initials.
*/
function checkInitials(&$creator, $initialsStyle, $firstNameInitial)
{
/**
* Format firstname
*/
if ($creator['firstname'] && !$firstNameInitial) {
// Full name
$firstName = stripslashes($creator['firstname']);
} else {
if ($creator['firstname']) {
$fn = split(" ", stripslashes($creator['firstname']));
$firstTime = TRUE;
foreach ($fn as $name) {
if ($firstTime) {
$firstNameInitialMake = UTF8::utf8_strtoupper(UTF8::utf8_substr(trim($name), 0, 1));
$firstTime = FALSE;
} else {
$initials[] = UTF8::utf8_strtoupper(UTF8::utf8_substr(trim($name), 0, 1));
}
}
if (isset($initials)) {
if ($creator['initials']) {
$creator['initials'] = join(" ", $initials) . ' ' . $creator['initials'];
} else {
$creator['initials'] = join(" ", $initials);
}
}
}
}
/**
* Initials are stored as space-delimited characters.
* If no initials, return just the firstname or its initial in the correct format.
*/
if (!$creator['initials']) {
if (isset($firstName)) {
// full first name only
return $firstName;
}
if (isset($firstNameInitialMake) && $initialsStyle > 1) {
// First name initial with no '.'
return $firstNameInitialMake;
}
if (isset($firstNameInitialMake)) {
// First name initial with '.'
return $firstNameInitialMake . '.';
}
return '';
// nothing here
}
$initialsArray = explode(' ', $creator['initials']);
/**
* If firstname is initial only, prepend to array
*/
if (isset($firstNameInitialMake)) {
array_unshift($initialsArray, $firstNameInitialMake);
}
if ($initialsStyle == 0) {
// 'T. U. '
$initials = implode('. ', $initialsArray) . '.';
} else {
if ($initialsStyle == 1) {
// 'T.U.'
$initials = implode('.', $initialsArray) . '.';
} else {
if ($initialsStyle == 2) {
// 'T U '
$initials = implode(' ', $initialsArray);
} else {
// 'TU '
$initials = implode('', $initialsArray);
}
}
}
/**
* If we have a full first name, prepend it to $initials.
*/
if (isset($firstName)) {
return $firstName . ' ' . $initials;
}
return $initials;
//.........这里部分代码省略.........
示例2: utf8_ucfirst
/**
* This is a unicode aware replacement for ucfirst()
*
* @author Andrea Rossato <arossato@istitutocolli.org>
* @see ucfirst()
*/
static function utf8_ucfirst($str)
{
$fc = UTF8::utf8_substr($str, 0, 1);
return UTF8::utf8_strtoupper($fc) . UTF8::utf8_substr($str, 1, UTF8::utf8_strlen($str));
}