本文整理汇总了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;
}