0

これは私のモデルです

function get_news(){
        $this->db->select('*');
        $this->db->from('articles');
        $this->db->where('status' , 0);
        $this->db->limit(6);
        $this->db->order_by('created', 'desc');
        return $this->db->get()->result();  
    }

私のテーブルアークティクル

id----title----body----status---created

ここで、列の本文に、ビュー、コントローラー、またはこのモデルを編集する必要がある100文字のみを表示したい..

よろしくお願いします。

4

3 に答える 3

1

使用するsubstr

function get_news() {
    $this->db->select('*');
    $this->db->from('articles');
    $this->db->where('status' , 0);
    $this->db->limit(6);
    $this->db->order_by('created', 'desc');
    return substr($this->db->get()->result(), 0, 100); 
}
于 2013-04-16T05:21:02.950 に答える
1

Use substr

$content = substr($str, 0, 100);
于 2013-04-16T05:15:42.440 に答える
0

function最後の単語自体を切り取らずに特定の文字で文字列を切り取る必要がある場合は、常に a を使用します。この関数は、必要に応じて文字を減らすことでそれを処理します

function strSelect( $myString, $maxLength ) {
$out = "";
$s = explode( " ",$myString );
for( $i = 0, $cs = count( $s ); $i < $cs; $i++ ) {
    $out .= $s[$i]." ";
    if( isSet( $s[$i+1] ) && ( strlen( $out ) + strlen( $s[$i+1] ) ) > $maxLength ) {
        break;
    }
}
return rtrim( $out );

}

そして、次のように呼び出すことができます

return strSelect(($this->db->get()->result()), 100);  

substrまたは、 (ドキュメントはこちら)関数を使用して特定の番号で単純にカットできます

substr(($this->db->get()->result()), 0, 100);
于 2013-04-16T05:16:03.160 に答える