dqwyghl0649 2012-07-18 14:15 采纳率: 0%
浏览 18
已采纳

我需要在被切断的字段末尾添加“...”

I want description, resolution and additional_notes to get cut off when it gets longer than 6 words and then have the "..." with a link to "see full case". I only want this to show on the fields that got cut off, not the ones that are less than 6 words because the full field would already be showing. If you guys could please help me figure out how to do this it would make my day! thank you!

I have this query which so far only works to get the field to cut off at 6 words:

$sql = ("SELECT id, sso, case_status, assigned_to, updated, created, SUBSTRING_INDEX(additional_notes,' ',6) as additional_notes, SUBSTRING_INDEX(resolution,' ',6) as resolution, SUBSTRING_INDEX(description,' ',6) as description FROM rmstable2 WHERE sso LIKE '%{$sso}%'");

The results show up in a table sort of like this:

Description: php here
Resolution: php here
Additional Notes: php here
and so on...

  • 写回答

2条回答 默认 最新

  • douhutongvm382381 2012-07-18 14:34
    关注

    How about this:

    <?php
    
    $text = array(
        'some long texts with multiple words, more then seven',
        'some long texts with multiple words, more then seven',
        'some long texts with multiple words, more then seven'
    );
    
    $new_text = array();
    foreach ( $text as $key => $string ) {
        $words = explode( ' ', $string );
        for ( $k=0; $k<6; $k++ ) {
            if ( $words[ $k ] ) $new_text[ $key ] .= $words[ $k ] . ' ';
        }
        $new_text[ $key ] .= '...';
        # Or like this, if you don't need the space
        //$new_text[ $key ] = rtrim( $new_text[ $key ] ) . '...';
    
    }
    print_r( $new_text );
    
    ?>
    

    Output:

    Array
    (
        [0] => some long texts with multiple words, ...
        [1] => some long texts with multiple words, ...
        [2] => some long texts with multiple words, ...
    )
    

    Or a CSS way:

    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 200px;
    

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器