当前位置: 首页>>代码示例>>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;未经允许,请勿转载。