Advertisement
arijulianto

Ringkasan Artikel dengan PHP

Mar 12th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. // ambil ringkasan berdasarkan jumlah kata (default 100 kata pertama)
  2. function ringkasan($text,$len=100){
  3.     $text = strip_tags(trim($text));
  4.     $text = str_replace(array(" ","  ")," ",$text);
  5.     $text = trim(str_replace("  "," ",$text));
  6.     $eText = explode(" ",$text);
  7.     $nText = count($eText);
  8.     $output = "";
  9.     if($nText>$len){
  10.         for($i=0;$i<=$len;$i++)$output[] = $eText[$i];
  11.         $output = implode(" ",$output)."...";
  12.     }else{
  13.         $output = $text;
  14.     }
  15.     $output = trim($output);
  16.     return $output;
  17. }
  18.  
  19. // ambil hanya beberapa karakter (default 100 karakter pertama)
  20. function potongText($text,$len=100){
  21.     $text = strip_tags(trim($text));
  22.     $text = str_replace(array("&nbsp;","  ")," ",$text);
  23.     $text = trim(str_replace("  "," ",$text));
  24.     $nText = strlen($text);
  25.     if($nText>$len){
  26.         $output = substr(0,$len,$text)."...";
  27.     }else{
  28.         $output = $text;
  29.     }
  30.     return $output;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement