当前位置: 首页>>代码示例>>PHP>>正文


PHP mb_strwidth函数代码示例

本文整理汇总了PHP中mb_strwidth函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_strwidth函数的具体用法?PHP mb_strwidth怎么用?PHP mb_strwidth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mb_strwidth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: limit

 /**
  * Limit the number of characters in a string.
  *
  * @param string $value
  * @param int    $limit
  * @param string $end
  *
  * @return string
  */
 public static function limit(string $value, int $limit = 100, string $end = '...') : string
 {
     if (mb_strwidth($value, 'UTF-8') <= $limit) {
         return $value;
     }
     return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
 }
开发者ID:narrowspark,项目名称:framework,代码行数:16,代码来源:Str.php

示例2: spa_display_member_roll

function spa_display_member_roll($members, $text1, $text2)
{
    $out = '';
    $cap = '';
    $first = true;
    $out .= '<fieldset class="sfsubfieldset">';
    $out .= '<legend>' . $text1 . '</legend>';
    if ($members) {
        $out .= '<p><b>' . count($members) . ' ' . spa_text('member(s) in this user group') . '</b></p>';
        for ($x = 0; $x < count($members); $x++) {
            if (strncasecmp($members[$x]->display_name, $cap, 1) != 0) {
                if (!$first) {
                    $out .= '</ul>';
                }
                $cap = substr($members[$x]->display_name, 0, 2);
                if (function_exists('mb_strwidth')) {
                    if (mb_strwidth($cap) == 2) {
                        $cap = substr($cap, 0, 1);
                    }
                } else {
                    $cap = substr($cap, 0, 1);
                }
                $out .= '<p style="clear:both;"></p><hr /><h4>' . strtoupper($cap) . '</h4>';
                $out .= '<ul class="memberlist">';
                $first = false;
            }
            $out .= '<li>' . sp_filter_name_display($members[$x]->display_name) . '</li>';
        }
        $out .= '</ul>';
    } else {
        $out .= $text2;
    }
    $out .= '</fieldset>';
    return $out;
}
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:35,代码来源:spa-ahah-usergroups.php

示例3: smarty_modifier_truncate_cn

/**
 * Smarty truncate for cn modifier plugin
 *
 * Type:     modifier<br>
 * Name:     truncate<br>
 * Purpose:  Truncate a string to a certain length if necessary,
 *           optionally splitting in the middle of a word, and
 *           appending the $etc string or inserting $etc into the middle.
 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
 *          truncate (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param integer
 * @param string
 * @param boolean
 * @param boolean
 * @return string
 */
function smarty_modifier_truncate_cn($string, $length = 80, $charset = 'UTF-8', $etc = '...')
{
    if (mb_strwidth($string, 'UTF-8') < $length) {
        return $string;
    }
    return mb_strimwidth($string, 0, $length, '', $charset) . $etc;
}
开发者ID:huqq1987,项目名称:clone-lemon,代码行数:25,代码来源:modifier.truncate_cn.php

示例4: str_limit

 function str_limit($value, $limit = 100, $end = '...')
 {
     if (mb_strwidth($value, 'UTF-8') <= $limit) {
         return $value;
     }
     return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
 }
开发者ID:kajamydeen75,项目名称:urf-master,代码行数:7,代码来源:misc_helper.php

示例5: cut

function cut($str)
{
    if (mb_strwidth($str, 'UTF-8') > 30) {
        $i = mb_strlen($str, 'UTF-8') % 2 ? (mb_strlen($str, 'UTF-8') + 1) / 2 : mb_strlen($str, 'UTF-8') / 2;
        do {
            $k = mb_strwidth(mb_substr($str, 0, $i, 'UTF-8'), 'UTF-8') - mb_strwidth(mb_substr($str, $i, 30, 'UTF-8'), 'UTF-8');
            echo "k={$k}, <br />";
            if ($k > 1) {
                --$i;
            } elseif ($k < 1 && $k != 0) {
                ++$i;
            }
        } while (abs($k) > 2);
        while (preg_match("/^[a-zA-Z\\s]+\$/", mb_substr($str, $i, 1, 'UTF-8'))) {
            ++$i;
        }
        if (strpos(mb_substr($str, $i - 2, 4, 'UTF-8'), " ")) {
            if (mb_substr($str, $i, 1, 'UTF-8') == ' ') {
                $str2 = mb_substr($str, $i + 1, 30, 'UTF-8');
                return str_replace(" {$str2}", "}\\underBlank{" . $str2, $str);
            } elseif (mb_substr($str, $i - 1, 1, 'UTF-8') == ' ') {
                $str2 = mb_substr($str, $i, 30, 'UTF-8');
                return str_replace(" {$str2}", "}\\underBlank{" . $str2, $str);
            } elseif (mb_substr($str, $i + 1, 1, 'UTF-8') == ' ') {
                $str2 = mb_substr($str, $i + 2, 30, 'UTF-8');
                return str_replace(" {$str2}", "}\\underBlank{" . $str2, $str);
            }
        }
        $str2 = mb_substr($str, $i, 30, 'UTF-8');
        return str_replace($str2, "}\\underBlank{" . $str2, $str);
    }
    return $str;
}
开发者ID:zogodo,项目名称:weibin,代码行数:33,代码来源:replaceTex.php

示例6: NormalizeNameItem

 /**
  * Normalizes a single name item
  * @param string $strNameItem
  * @return string
  */
 public static function NormalizeNameItem($strNameItem)
 {
     $strNameItem = trim($strNameItem);
     if (!mb_strlen($strNameItem)) {
         return null;
     }
     $strNameItem = mb_strtolower($strNameItem);
     $strFinal = '';
     $intLength = mb_strlen($strNameItem);
     for ($i = 0; $i < $intLength; $i++) {
         $strCurrent = mb_substr($strNameItem, $i, 1);
         foreach (self::$Internationalized as $strNormalized => $strInternationalized) {
             if (mb_strpos($strInternationalized, $strCurrent) !== false) {
                 $strCurrent = $strNormalized;
             }
         }
         if (mb_strwidth($strCurrent) == 1) {
             $intOrd = ord($strCurrent);
             if ($intOrd >= ord('a') && $intOrd <= ord('z')) {
                 $strFinal .= $strCurrent;
             }
         }
     }
     return $strFinal;
 }
开发者ID:alcf,项目名称:chms,代码行数:30,代码来源:NameItem.class.php

示例7: execute

 function execute($requests)
 {
     $u = $GLOBALS['AUTH']->uid();
     // --- リクエスト変数
     $subject = $requests['subject'];
     $body = $requests['body'];
     $public_flag = util_cast_public_flag_diary($requests['public_flag']);
     $category = $requests['category'];
     $is_comment_input = $requests['is_comment_input'];
     // ----------
     $sessid = session_id();
     t_image_clear_tmp($sessid);
     $upfiles = array(1 => $_FILES['upfile_1'], $_FILES['upfile_2'], $_FILES['upfile_3']);
     $tmpfiles = array(1 => '', '', '');
     $filesize = 0;
     foreach ($upfiles as $key => $upfile) {
         if (!empty($upfile) && $upfile['error'] !== UPLOAD_ERR_NO_FILE) {
             if (!($image = t_check_image($upfile))) {
                 $_REQUEST['msg'] = '画像は' . IMAGE_MAX_FILESIZE . 'KB以内のGIF・JPEG・PNGにしてください';
                 openpne_forward('pc', 'page', 'h_diary_add');
                 exit;
             } else {
                 $filesize += $image['size'];
                 $tmpfiles[$key] = t_image_save2tmp($upfile, $sessid, "d_{$key}", $image['format']);
             }
         }
     }
     $category_list = array_unique(preg_split('/\\s+/', $category));
     if (count($category_list) > 5) {
         $_REQUEST['msg'] = 'カテゴリは5つまでしか指定できません';
         openpne_forward('pc', 'page', 'h_diary_add');
         exit;
     }
     foreach ($category_list as $value) {
         if (mb_strwidth($value) > 20) {
             $_REQUEST['msg'] = 'カテゴリはひとつにつき全角10文字(半角20文字)以内で入力してください';
             openpne_forward('pc', 'page', 'h_diary_add');
             exit;
         }
     }
     // 画像アップロード可能サイズチェック
     if ($filesize) {
         $result = util_image_check_add_image_upload($filesize, $u, 'diary');
         if ($result) {
             if ($result == 2) {
                 $result = 3;
             }
             $msg = util_image_get_upload_err_msg($result);
             $_REQUEST['msg'] = $msg;
             openpne_forward('pc', 'page', 'h_diary_add');
             exit;
         }
     }
     $this->set('inc_navi', fetch_inc_navi('h'));
     //プロフィール
     $this->set("member", db_member_c_member4c_member_id($u));
     $form_val = array("subject" => $subject, "body" => $body, "public_flag" => $public_flag, "upfile_1" => $_FILES['upfile_1'], "upfile_2" => $_FILES['upfile_2'], "upfile_3" => $_FILES['upfile_3'], "tmpfile_1" => $tmpfiles[1], "tmpfile_2" => $tmpfiles[2], "tmpfile_3" => $tmpfiles[3], "category" => join(" ", $category_list), "is_comment_input" => $is_comment_input);
     $this->set("form_val", $form_val);
     return 'success';
 }
开发者ID:KimuraYoichi,项目名称:PukiWiki,代码行数:60,代码来源:h_diary_add_confirm.php

示例8: strlen

 /**
  * Returns the length of a string, using mb_strwidth if it is available.
  *
  * @param string $string The string to check its length
  *
  * @return int The length of the string
  */
 public static function strlen($string)
 {
     if (false === ($encoding = mb_detect_encoding($string, null, true))) {
         return strlen($string);
     }
     return mb_strwidth($string, $encoding);
 }
开发者ID:saj696,项目名称:pipe,代码行数:14,代码来源:Helper.php

示例9: msubstr

/**
 * 字符串截取,支持中文和其他编码
 * @static
 * @access public
 * @param string $str 需要转换的字符串
 * @param string $start 开始位置
 * @param string $length 截取长度
 * @param string $charset 编码格式
 * @param string $suffix 截断显示字符
 * @return string
 */
function msubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = false)
{
    if (function_exists("mb_strimwidth")) {
        $slice = mb_strimwidth($str, $start, $length, '', $charset);
        // mb_strimwidth 截取字符串 中文算2个字节,英文算1个
    } elseif (function_exists('mb_substr')) {
        $slice = mb_substr($str, $start, $length, $charset);
    } elseif (function_exists("iconv_substr")) {
        $slice = iconv_substr($str, $start, $length, $charset);
    } else {
        $re['utf-8'] = "/[-]|[�-�][�-�]|[�-�][�-�]{2}|[�-�][�-�]{3}/";
        $re['gb2312'] = "/[-]|[�-�][�-�]/";
        $re['gbk'] = "/[-]|[�-�][@-�]/";
        $re['big5'] = "/[-]|[�-�]([@-~]|�-�])/";
        preg_match_all($re[$charset], $str, $match);
        $slice = join("", array_slice($match[0], $start, $length));
    }
    if ($suffix) {
        return mb_strwidth($slice, $charset) > $length ? $slice : $slice . '...';
        // mb_strwidth 计算字符串长度 中文算2个字节,英文算1个
    } else {
        return $slice;
    }
    //    return $suffix ? $slice.'...' : $slice;
}
开发者ID:novnan,项目名称:meiju,代码行数:36,代码来源:functions.php

示例10: stringCompact

/**
 * Compact a string to a maximum length
 *
 * @access public
 * @param string $str String to compact
 * @param integer $length Length to trim at
 * @return string Compact string; otherwise, original string
 */
function stringCompact($str, $length = 0)
{
    // mb_strwidth is better than using mb_strlen. See PHP docs for more details
    if ($length === 0 || mb_strwidth($str) <= $length) {
        return $str;
    }
    return mb_strimwidth($str, 0, $length, '...');
}
开发者ID:softwarespot,项目名称:PHP-Snippets,代码行数:16,代码来源:stringCompact.php

示例11: getSubStr

 /**
  * get substr support chinese
  * return $str
  */
 static function getSubStr($str, $length, $postfix = '...', $encoding = 'UTF-8')
 {
     $realLen = mb_strwidth($str, $encoding);
     if (!is_numeric($length) or $length * 2 >= $realLen) {
         return htmlspecialchars($str, ENT_QUOTES, $encoding);
     }
     $str = mb_strimwidth($str, 0, $length * 2, $postfix, $encoding);
     return htmlspecialchars($str, ENT_QUOTES, $encoding);
 }
开发者ID:jianyongchen,项目名称:smpss,代码行数:13,代码来源:SUtil.class.php

示例12: validateHasMultiByte

 /**
  *
  * @param $attribute
  * @param $value
  * @param $parameters
  * @return bool
  */
 public function validateHasMultiByte($attribute, $value, $parameters)
 {
     $len = mb_strlen($value, 'UTF-8');
     $wdt = mb_strwidth($value, 'UTF-8');
     if (20 < $wdt - $len) {
         return true;
     }
     return false;
 }
开发者ID:picolit,项目名称:bbs,代码行数:16,代码来源:CustomValidator.php

示例13: znStrLength

 public static function znStrLength($str, $min, $max = 999999)
 {
     $length = mb_strwidth($str);
     if ($length >= $min && $length <= $max) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:liaohui1080,项目名称:oneMail,代码行数:9,代码来源:function.php

示例14: strlen

 /**
  * Returns the length of a string, using mb_strwidth if it is available.
  *
  * @param string $string The string to check its length
  *
  * @return int The length of the string
  */
 public static function strlen($string)
 {
     if (!function_exists('mb_strwidth')) {
         return strlen($string);
     }
     if (false === ($encoding = mb_detect_encoding($string))) {
         return strlen($string);
     }
     return mb_strwidth($string, $encoding);
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:17,代码来源:Helper.php

示例15: substr

 /**
  * 裁剪字符串,加“...”
  */
 static function substr($str, $length, $endfix = '...')
 {
     mb_internal_encoding("UTF-8");
     $str_length = mb_strwidth($str);
     if ($str_length > $length * 2) {
         return mb_substr($str, 0, $length) . $endfix;
     } else {
         return $str;
     }
 }
开发者ID:Debenson,项目名称:openwan,代码行数:13,代码来源:util.php


注:本文中的mb_strwidth函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。