Script fungsi sederhana untuk melakukan pemotongan string atau kalimat secara otomatis pembulatan per kata;
Skrinya sebagai berikut :
<font COLOR="#ff6600"><?php</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> /**</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> * @author Hadi Suwantoro</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> * @copyright 2008</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> *</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> * Cutting String</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> *</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> * @param string $ string ,</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> * @param length $ length of caracter for cutting</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> * @return string after cutting</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> */</font>
function cut_string(<font COLOR="#000000">$string,$length</font>)
{<font COLOR="#ff6600">
</font> for($i=0;$i<=$length;$i++)
{
if (<font COLOR="#000000">$string[$i]==" "</font>)
{<font COLOR="#000000">$last_space_pos = $i;</font>}
}
return substr(<font COLOR="#000000">$string,0,$last_space_pos</font>);
}<font COLOR="#ff6600"> </font><font COLOR="#ff6600">?></font><code>
Contoh penggunaan :
<font COLOR="#ff6600"><?php</font><font COLOR="#ff6600">
</font><font COLOR="#ff6600"> /**</font><font COLOR="#ff6600">
</font>
<font COLOR="#000000">$String</font> = "Hosting Murah 50MB Bandwidth 1.5Gb hanya 25.000/tahun";
$str_result = cut_string($String,20);
echo $str_result;
<font COLOR="#ff6600">?></font>
Semoga membantu.





