Web Stats Web Hosting Blogs - BlogCatalog Blog Directory TopOfBlogs

Masukan email anda untuk mendapatkan artikel terbaru:

hab.la

PHP Automatic Cut String Function

Script fungsi sederhana untuk melakukan pemotongan string atau kalimat secara otomatis pembulatan per kata;

Skrinya sebagai berikut :

<font COLOR="#ff6600">&lt;?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&lt;=$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">?&gt;</font><code>

Contoh penggunaan :

<font COLOR="#ff6600">&lt;?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">?&gt;</font>

Semoga membantu.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Incoming search terms for the article:

Related posts:

  1. linux command mencari string pada file Mencari String pada file dengan ekstensi tertentu $ grep “mystring”...
  2. Smarty Plugin untuk FCKeditor html WYSIWYG Editor Anda sudah mengenal Smarty dan FCKEditor jika sudah maka Anda...
  3. Menghindari email masuk SPAM folder Yahoo dan Google dengan PHP Mailler Sebenarnya bahasan ini sudah tidak asing lagi dan sudah banyak...
  4. Hosting Gratis Dalam Rangka Ulang Tahun Surabaya ke-715 Heoreee…!!!! Bertambahnya umur tentunya harus bertambah pula kemantaban Surabaya dalam...
  5. awas Malware money2008.org dan Js/Downloader menginjeksi situs anda beberapa waktu lalu satu situs yang sempat saya kelola dan...

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">