mb_wordwrap

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

指定したカラム幅で文字列をワードラップします(デフォルトは80)。 第2パラメータには、次の行にワードラップするために使用される文字列を 指定する事が出来ます(デフォルトは\n)。デフォルトでは単語の境界でワードラップを行います。 厳密な文字数でワードラップしたい場合は第3パラメータにtrueを渡します。 Artisan Smartyオリジナルであり、マルチバイト文字に対応しています。

例 5-22. mb_wordwrap

<?php
    
$smarty
= new Smarty;
$smarty->assign('articleTitle', "Blind woman gets new kidney from dad she hasn't seen in years.");
$smarty->display('index.tpl');

?>

index.tpl :

{$articleTitle}

{$articleTitle|mb_wordwrap:30}
    
{$articleTitle|mb_wordwrap:20}
    
{$articleTitle|mb_wordwrap:30:"<br />\n"}
    
{$articleTitle|mb_wordwrap:30:"\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 kidney
from dad she hasn't seen in
years.