Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
mysql で RSS スクリプトを作成していますが、データベースに余分なフィールドは必要ありません。ページにエコーアウトされた文字数?
もちろん、この構文ではなく、次のようなものです。
echo(limit($row['newsBody'], 1000));
これを行うのに 15 行のコードが必要かどうかは気にしません ;)
PS limit() は関数だと確信しています。教えないでください..単なる例です;)
前もって感謝します!
echo(substr($row['newsBody'], 0, 1000));
機能はsubstrあなたが探しているものです。またはmb_substr、マルチバイト文字列を扱っている場合に使用できます。
substr
mb_substr
あなたはこれを行うことができます
$body = $row['newsBody']; $length = strlen($body) > 1000 ? 1000 : strlen($1000); echo substr($body,0, $length);
最初の 1000 文字またはメッセージ全体のうち短い方を出力します。
substr( $string, 0, 1000 );