zoukankan      html  css  js  c++  java
  • PHP中文字数限制:中文字符串截取(mb_substr)

    一、中文截取:mb_substr()

    mb_substr( $str, $start, $length, $encoding )

    $str,需要截断的字符串
    $start,截断开始处,起始处为0
    $length,要截取的字数
    $encoding,网页编码,如utf-8,GB2312,GBK

    具体使用:

    <?php 
    $str='博客站长:http://www.cnblogs.com'; 
    echo mb_substr($str,0,4,'utf-8');//截取头5个字,假定此代码所在php文件的编码为utf-8 
    ?> 
    结果显示:博客站长

    二、获取中文长度:mb_strlen()

    mb_strlen( $str, $encoding )

    $str,要计算长度的字符串
    $encoding,网页编码,如utf-8,GB2312,GBK

    <?php 
    $str='博客站长:http://www.cnblogs.net'; 
    echo mb_strlen($str,'utf-8');//假定此代码所在php文件的编码为utf-8 
    ?> 
    结果显示:24 //假定

    三、标签上的使用:

    <p class='tese'>班型特色:{:mb_substr($v['banchetese'],0,35,'utf-8')}...</p>
  • 相关阅读:
    E. You Are Given Some Strings...
    神奇函数
    AC自动机再加强版
    AC自动机2
    AC自动机
    three arrays
    permutation 2
    string matching
    permutation 1
    equation
  • 原文地址:https://www.cnblogs.com/e0yu/p/7494623.html
Copyright © 2011-2022 走看看