當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UTF8::lengthAsEm方法代碼示例

本文整理匯總了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));
}
開發者ID:hinablue,項目名稱:TextCube,代碼行數:29,代碼來源:index.php

示例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;
 }
開發者ID:jinbonetwork,項目名稱:collective-agreement-database,代碼行數:34,代碼來源:UTF8.class.php


注:本文中的UTF8::lengthAsEm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。