str_limit($one->body, $limit = 200, $end = '...')
私はLaravel 5.2 str_limit()
ヘルパー機能を使用しています。言葉を壊さないことは可能ですか?L5.2 str_limit壊れた言葉
str_limit($one->body, $limit = 200, $end = '...')
私はLaravel 5.2 str_limit()
ヘルパー機能を使用しています。言葉を壊さないことは可能ですか?L5.2 str_limit壊れた言葉
この機能では不可能です。あなたはあなたのコードにPHPコードを使用するか、または独自のヘルパーを作成する必要があります
:しかし、あなたは上の興味深い情報を見つけることができます。まあ
あなたは言葉を壊すことなく、文字の与えられた数の文字列の長さを制限したい場合、あなたは、PHP word_wrap機能
を使用することができますこれは、文字列の特定の文字数を返します。 'break'引数は、文字列を分割する文字を指定します。 'cut'引数は、文字列が単語の前または前に分割されることを指定します。次のように
あなたはそれを使用することができます。
/** This will add the "@" character after every $character_count characters */
$wrapped_string = word_wrap($string, $character_count, "@", false);
/** This will convert the wrapped string to an array */
$wrapped_string_arr = explode("@", $wrapped_string);
/** The limitted string without breaking word*/
$limitted_string = $wrapped_string_arr[0];
http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest特定キャラクターの数 –