Memotong Paragraf Dengan Jumlah Kata Tertentu di PHP

php

Di bawah ini merupakan script PHP untuk memotong paragraf atau konten kalimat di web.

<?php
function Cut_Words($sentence,$word_count)
{
$space_count = 0;
$print_string = ”;
for($i=0;$i<strlen($sentence);$i++)
{
if($sentence[$i]==’ ‘)
$space_count ++;
$print_string .= $sentence[$i];
if($space_count == $word_count)
break;
}
echo $print_string;
}

$sentence = ‘Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?’;

Cut_Words($sentence,13);

?>

Pemanggilan fungsi Cut_Words($sentence,13) adalah memotong konten kalimat pada $sentence menjadi 13 kata.

a simple man

Tagged with:
Posted in Knowledge, Tips
3 comments on “Memotong Paragraf Dengan Jumlah Kata Tertentu di PHP
  1. taminteckom says:

    Oke bgt tutoriallnya,,,,,, btw tampilan blognya keren, gmn teuh biar blog z bisa keren jg,,, maklum masih pemula,,,,,,,,, mohon bantuannya,,,,,

  2. thank’s kang infonya sangat membantu..🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

July 2010
M T W T F S S
« Mar   Aug »
 1234
567891011
12131415161718
19202122232425
262728293031  
Blog Stats
  • 72,745 hits
%d bloggers like this: