本文整理匯總了PHP中UTF8::lengthAsEm方法的典型用法代碼示例。如果您正苦於以下問題:PHP UTF8::lengthAsEm方法的具體用法?PHP UTF8::lengthAsEm怎麽用?PHP UTF8::lengthAsEm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UTF8
的用法示例。
在下文中一共展示了UTF8::lengthAsEm方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: RefererURLBeautifier_handler
function RefererURLBeautifier_handler($target, $mother)
{
$keyword = false;
if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[2]));
} else {
if (strpos($mother['host'], 'images.google.') !== false && preg_match('/%3Fsearch%3D([^&]+)/i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
} else {
if (strpos($mother['host'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
} else {
if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
}
}
}
}
if (!UTF8::validate($keyword)) {
$keyword = UTF8::correct(UTF8::bring($keyword));
}
$keyword = UTF16UrlDecode($keyword);
$url = rawurldecode(substr($mother['url'], 7));
if (!UTF8::validate($url)) {
$url = UTF8::correct(UTF8::bring($url));
}
//return '<img src="http://'.$mother['host'].'/favicon.ico" width="16" height="16" alt="Favicon" onerror="this.parentNode.removeChild(this)" style="vertical-align: middle"/> ' . (($keyword) ? '<span style="font-weight: bold; color: #594">['.htmlspecialchars($keyword).']</span> ' . UTF8::lessenAsEm($url, 65 - UTF8::lengthAsEm($keyword)) : UTF8::lessenAsEm($url, 65));
return $keyword ? '<span style="font-weight: bold; color: #594">[' . htmlspecialchars($keyword) . ']</span> ' . htmlspecialchars(UTF8::lessenAsEm($url, 70 - UTF8::lengthAsEm($keyword))) : htmlspecialchars(UTF8::lessenAsEm($url, 70));
}
示例2: lessenAsEm
static function lessenAsEm($str, $ems, $tail = '...')
{
if (function_exists('mb_strimwidth')) {
return mb_strimwidth($str, 0, $ems - 1, $tail, 'utf-8');
}
if (UTF8::lengthAsEm($str) <= $ems) {
$tail = '';
} else {
$ems -= strlen($tail);
}
$len = strlen($str);
for ($i = $adapted = 0; $i < $len; $adapted = $i) {
$high = ord($str[$i]);
if ($high < 0x80) {
$i += 1;
$ems -= 1;
} else {
if ($high < 0xe0) {
$i += 2;
} else {
if ($high < 0xf0) {
$i += 3;
} else {
$i += 4;
}
}
$ems -= 2;
}
if ($ems < 0) {
break;
}
}
return trim(substr($str, 0, $adapted)) . $tail;
}