mb_strimwidth

パラメータの位置必須デフォルト概要
1integerNo0開始位置のオフセット
2integerNo100切り捨てを行うキャラクタ数
3stringNo切り捨てが発生した際に終端に付加するキャラクタ

文字列を開始位置のオフセットから指定した幅で丸めます。 mb_strim_widthのラッパーです。 Artisan Smartyオリジナルであり、マルチバイト文字に対応しています。

例 5-20. mb_strimwidth

<?php
    
$smarty
= new Smarty;
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
$smarty->display('index.tpl');

?>

index.tpl :

{$articleTitle}
{$articleTitle|mb_strimwidth}
{$articleTitle|mb_strimwidth:0:30}
{$articleTitle|mb_strimwidth:0:30:""}
{$articleTitle|mb_strimwidth:0:30:"---"}
{$articleTitle|mb_strimwidth:0:30:""}
{$articleTitle|mb_strimwidth:0:30:"..."}

出力 :

Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after E…
Two Sisters Reunite after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...