• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP mb_strwidth函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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
  */
 protected function strlen($string)
 {
     if (!function_exists('mb_strwidth')) {
         return strlen($string);
     }
     if (false === ($encoding = mb_detect_encoding($string, null, true))) {
         return strlen($string);
     }
     return mb_strwidth($string, $encoding);
 }
开发者ID:Herriniaina,项目名称:iVarotra,代码行数:17,代码来源:Helper.php


示例17: string_cut

function string_cut($String, $Length, $Title = 0, $Dots = 1)
{
    if (!$Length) {
        return $String;
    }
    if (!function_exists('mb_substr')) {
        return strlen($String) > $Length + 3 || !$Dots ? $Title ? '<span title="' . htmlspecialchars($String) . '">' . htmlspecialchars(substr_replace($String, $Dots ? '...' : '', $Length)) . '</span>' : htmlspecialchars(substr_replace($String, $Dots ? '...' : '', $Length)) : htmlspecialchars($String);
    } else {
        return mb_strwidth($String, 'UTF-8') > $Length + 3 || !$Dots ? $Title ? '<span title="' . htmlspecialchars($String) . '">' . htmlspecialchars(mb_substr($String, 0, $Length, 'UTF-8')) . ($Dots ? '...' : '') . '</span>' : htmlspecialchars(mb_substr($String, 0, $Length, 'UTF-8')) . ($Dots ? '...' : '') : htmlspecialchars($String);
    }
}
开发者ID:brian-clemont,项目名称:phpos,代码行数:11,代码来源:functions.php


示例18: execute

 function execute($requests)
 {
     $errors = array();
     if (!db_common_is_mailaddress($requests['pc_address']) || is_ktai_mail_address($requests['pc_address'])) {
         $errors[] = 'PCメールアドレスを正しく入力してください';
     }
     if (OPENPNE_AUTH_MODE == 'email') {
         if ($requests['password'] !== $requests['password2']) {
             $errors[] = 'パスワードが一致していません';
         }
     }
     if ($requests['admin_password'] !== $requests['admin_password2']) {
         $errors[] = '管理用パスワードが一致していません';
     }
     if (OPENPNE_AUTH_MODE == 'slavepne') {
         $auth_config = get_auth_config(false);
         $storage = Auth::_factory($auth_config['storage'], $auth_config['options']);
         $result = $storage->fetchData($requests['username'], $requests['password'], false);
         if ($result !== true) {
             $errors[] = 'ログインIDまたはパスワードが一致しません';
         }
     }
     if (OPENPNE_AUTH_MODE == 'pneid') {
         if (is_null($requests['username']) || $requests['username'] === '') {
             $errors[] = 'ログインIDを入力してください';
         } elseif (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\\-_]+[a-zA-Z0-9]$/i', $requests['username'])) {
             $errors[] = 'ログインIDは4~30文字の半角英数字、記号(アンダーバー「_」、ハイフン「-」)で入力してください';
         } elseif (mb_strwidth($requests['username'], 'UTF-8') < 4) {
             $errors[] = "ログインIDは半角4文字以上で入力してください";
         } elseif (mb_strwidth($requests['username'], 'UTF-8') > 30) {
             $errors[] = "ログインIDは半角30文字以内で入力してください";
         }
     }
     if ($errors) {
         $this->handleError($errors);
     }
     // c_admin_config: SNS_NAME
     $data = array('name' => 'SNS_NAME', 'value' => $requests['SNS_NAME']);
     db_insert('c_admin_config', $data);
     // c_member_secure
     $data = array('c_member_id' => 1, 'hashed_password' => md5($requests['password']), 'hashed_password_query_answer' => '', 'pc_address' => t_encrypt($requests['pc_address']), 'ktai_address' => '', 'regist_address' => t_encrypt($requests['pc_address']), 'easy_access_id' => '');
     if (OPENPNE_AUTH_MODE == 'slavepne' && !IS_SLAVEPNE_EMAIL_REGIST) {
         $data['ktai_address'] = t_encrypt('[email protected]');
     }
     db_insert('c_member_secure', $data);
     // c_admin_user
     $data = array('username' => $requests['admin_username'], 'password' => md5($requests['admin_password']), 'auth_type' => 'all');
     db_insert('c_admin_user', $data);
     if (OPENPNE_AUTH_MODE != 'email') {
         db_member_insert_username(1, $requests['username']);
     }
     openpne_redirect('setup', 'page_setup_done');
 }
开发者ID:KimuraYoichi,项目名称:PukiWiki,代码行数:53,代码来源:setup.php


示例19: Cell_AutoFontSize

 /**
  * @param $fontSize
  * @param int $w
  * @param int $h
  * @param string $txt
  * @param int $border
  * @param int $ln
  * @param string $align
  * @param bool $fill
  * @param string $link
  * @param int $stretch
  * @param bool $ignore_min_height
  * @param string $calign
  * @param string $valign
  */
 public function Cell_AutoFontSize($fontSize, $w = 0, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M')
 {
     // 幅によってフォントサイズを6段階で縮小する。
     $size = $fontSize;
     for ($i = 0; $size > 0; $i++) {
         //if ( $w >= ( mb_strlen(trim($txt),'UTF-8')) * ($fontSize - $i) * 0.35 ) {
         if ($w >= mb_strwidth(trim($txt), 'UTF-8') * ($fontSize - $i) * 0.228) {
             break;
         }
         $size = $fontSize - $i;
     }
     $this->SetFontSize($size);
     $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
 }
开发者ID:ateliee,项目名称:php_lib,代码行数:29,代码来源:class_pdf.php


示例20: _render

 /**
  * Output a row.
  *
  * @param array $row The row to output.
  * @param array $widths The widths of each column to output.
  * @param array $options Options to be passed.
  * @return void
  */
 protected function _render(array $row, $widths, $options = [])
 {
     if (count($row) === 0) {
         return;
     }
     $out = '';
     foreach ($row as $i => $column) {
         $pad = $widths[$i] - mb_strwidth($column);
         if (!empty($options['style'])) {
             $column = $this->_addStyle($column, $options['style']);
         }
         $out .= '| ' . $column . str_repeat(' ', $pad) . ' ';
     }
     $out .= '|';
     $this->_io->out($out);
 }
开发者ID:rlugojr,项目名称:cakephp,代码行数:24,代码来源:TableHelper.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP mb_subStr函数代码示例发布时间:2022-05-15
下一篇:
PHP mb_strtoupper函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap