wordwrap (変数の修飾子) - PHPプロ!マニュアル

Smartyマニュアル

変数の修飾子 - wordwrap

wordwrap

指定したカラム幅で文字列をワードラップします(デフォルトは80)。 第2パラメータには、次の行にワードラップするために使用される文字列を指定する事が出来ます (デフォルトは "\n" )。 デフォルトでは、wordwrap は単語の境界でワードラップを行います。 厳密な文字数でワードラップしたい場合は第3パラメータに TRUE を渡します。 これは PHP の wordwrap() 関数と同義です。

パラメータの位置 必須 デフォルト 概要
1 integer No 80 ワードラップするカラム幅
2 string No \n ワードラップに使用される文字列
3 boolean No FALSE ワードラップを単語の境界で行うか(FALSE )、 厳密なキャラクタ数で行うか(TRUE )

例 5-23. wordwrap

<?php

$smarty
->assign('articleTitle',
                
"Blind woman gets new kidney from dad she hasn't seen in years."
               
);

?>

テンプレート

{$articleTitle}

{$articleTitle|wordwrap:30}

{$articleTitle|wordwrap:20}

{$articleTitle|wordwrap:30:"<br />\n"}

{$articleTitle|wordwrap:26:"\n":true}

出力

Blind woman gets new kidney from dad she hasn't seen in years.

Blind woman gets new kidney
from dad she hasn't seen in
years.

Blind woman gets new
kidney from dad she
hasn't seen in
years.

Blind woman gets new kidney<br />
from dad she hasn't seen in<br />
years.

Blind woman gets new kidn
ey from dad she hasn't se
en in years.

nl2br および {textformat} も参照してください。



Pick Up Q&A

Q
マジッククォートとmysql_real_escape_string
 このエントリーをはてなブックマークに追加 
A
magic_quotes_gpcでは、SQLインジェクション対処は十分できません。主な理由として、以下が上げられます。 ・magic_quotes_gpcは文字コードを考慮しないで処理するので、Shift_JISを使っている場合、SQLインジェ...

>>続きを読む

SQLインジェクション対策は時と場合で使う関数が変わります。その時にあったものを使いましょう。

▲解説者:岡本(アシアル株式会社 教育コーディネーター兼 システムエンジニア)