1

説明、解決策、および追加のメモが 6 語を超えると切り捨てられ、「...」に「完全なケースを表示」へのリンクが含まれるようにします。完全なフィールドが既に表示されているため、6 語未満のフィールドではなく、切り取られたフィールドにのみ表示するようにします。皆さんがこれを行う方法を理解するのを手伝っていただければ、それは私の一日になります! ありがとう!

私はこのクエリを持っていますが、これはこれまでのところ、フィールドを 6 単語で切り捨てるためにのみ機能します。

$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}%'");

結果は、次のような表形式で表示されます。

説明: ここに php
解決策: ここに php
追記事項: ここ
に php など...

4

2 に答える 2

1

これはどう:

<?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 );

?>

出力:

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

またはCSSの方法:

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

それが役立つことを願っています。

于 2012-07-18T14:34:55.050 に答える
0

PHP関数を使用しないのはなぜですか?

function cutLongWord($String='', $Length=20, $Suffix='...'){
    return (strlen($String) > $Length ? substr($String, 0, $Length).$Suffix : $String);
}   
于 2012-07-18T14:19:04.173 に答える