Home > Backend Development > PHP Tutorial > php arclist标签,截取字符如何在后面加上点点点

php arclist标签,截取字符如何在后面加上点点点

WBOY
Release: 2016-06-13 13:36:17
Original
1156 people have browsed it

php arclist标签,截取字符怎么在后面加上点点点
初学织梦啊
那个标签
dede:arclist titlelen=42 row=12}
 

  • [field:title/]

  • {/dede:arclist}
    怎么使超出42长度的后面自动加上...点点点啊

    ------解决方案--------------------
    也可以在从数据库里取title的时候,就截取
    SELECT id,left(title,42) as title from table
    ------解决方案--------------------
    探讨

    也可以在从数据库里取title的时候,就截取
    SELECT id,left(title,42) as title from table

    ------解决方案--------------------
    //实现中英文截取
    function cut_str($sourcestr, $cutlength = 10, $etc = '...')
    {
    $returnstr = '';
    $i = 0;
    $n = 0.0;
    $str_length = strlen($sourcestr); //字符串的字节数
    while ( ($n{
    $temp_str = substr($sourcestr, $i, 1);
    $ascnum = ord($temp_str); //得到字符串中第$i位字符的ASCII码
    if ( $ascnum >= 252) //如果ASCII位高与252
    {
    $returnstr = $returnstr . substr($sourcestr, $i, 6); //根据UTF-8编码规范,将6个连续的字符计为单个字符
    $i = $i + 6; //实际Byte计为6
    $n++; //字串长度计1
    }
    elseif ( $ascnum >= 248 ) //如果ASCII位高与248
    {
    $returnstr = $returnstr . substr($sourcestr, $i, 5); //根据UTF-8编码规范,将5个连续的字符计为单个字符
    $i = $i + 5; //实际Byte计为5
    $n++; //字串长度计1
    }
    elseif ( $ascnum >= 240 ) //如果ASCII位高与240
    {
    $returnstr = $returnstr . substr($sourcestr, $i, 4); //根据UTF-8编码规范,将4个连续的字符计为单个字符
    $i = $i + 4; //实际Byte计为4
    $n++; //字串长度计1
    }
    elseif ( $ascnum >= 224 ) //如果ASCII位高与224
    {
    $returnstr = $returnstr . substr($sourcestr, $i, 3); //根据UTF-8编码规范,将3个连续的字符计为单个字符
    $i = $i + 3 ; //实际Byte计为3
    $n++; //字串长度计1
    }
    elseif ( $ascnum >= 192 ) //如果ASCII位高与192
    {
    $returnstr = $returnstr . substr($sourcestr, $i, 2); //根据UTF-8编码规范,将2个连续的字符计为单个字符
    $i = $i + 2; //实际Byte计为2
    $n++; //字串长度计1
    }
    elseif ( $ascnum>=65 and $ascnum{
    $returnstr = $returnstr . substr($sourcestr, $i, 1);
    $i = $i + 1; //实际的Byte数仍计1个
    $n++; //但考虑整体美观,大写字母计成一个高位字符
    }
    elseif ( !(array_search($ascnum, array(37, 38, 64, 109 ,119)) === FALSE) ) //%,&,@,m,w 字符按1个字符宽
    {
    $returnstr = $returnstr . substr($sourcestr, $i, 1);
    $i = $i + 1; //实际的Byte数仍计1个
    $n++; //但考虑整体美观,这些字条计成一个高位字符
    }
    else //其他情况下,包括小写字母和半角标点符号
    {
    $returnstr = $returnstr . substr($sourcestr, $i, 1);
    $i = $i + 1; //实际的Byte数计1个
    $n = $n + 0.5; //其余的小写字母和半角标点等与半个高位字符宽...
    }
    }
    if ( $i {
    $returnstr = $returnstr . $etc; //超过长度时在尾处加上省略号
    }
    return $returnstr;
    }

    OR

    select * from tablename substring(title,1,10) as t

    ------解决方案--------------------
    首页上有一段代码,其实说白了就是
    自己加上...,何必要程序加
    PHP code
    
     {dede:arclist flag='h' limit='0,1'}
                            <h2><a href="%5Bfield:arcurl/%5D">[field:title/]</a></h2>
                            <p>[field:description function='cn_substr(@me,110)'/]...<a href="%5Bfield:arcurl/%5D">[查看全文]</a></p>
                            {/dede:arclist} <div class="clear">
                     
                  
                  
            
                </div>
    Copy after login
    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template