Просмотр файла system/inc/classes/substr.class.php

Размер файла: 0.98Kb
  1. <?php
  2.  
  3. /*
  4. * @function: Класс обрезки текста
  5. * @author: Shamsik
  6. * @$subclass->cutstring (Текст, Символы)
  7. */
  8.  
  9. class substr {
  10.  
  11.  
  12. function cutstring( $stranb, $lengthanb, $theend="..." ) {
  13.  
  14. if (strlen($stranb)>30) {$text2=substr($stranb, 0, $lengthanb);
  15.  
  16. $words=explode(" ", $text2);
  17. $words=array_reverse($words);
  18. array_splice($words,0,1);
  19. $alexxnb=0;
  20. for ($i=0; $i<count($words); $i++) {
  21. $i=$i-$alexxnb;
  22. if (substr($words[$i], -1)=="," OR substr($words[$i], -1)=="." OR substr($words[$i], -1)==":" OR substr($words[$i], -1)==";") {
  23. $words[$i]=substr($words[$i],0, strlen($words[$i])-1);
  24. };
  25. $wrd=$words[$i];
  26. if (strlen($wrd)<4){
  27. array_splice($words,$i,1);$alexxnb=1;
  28. } else {
  29. $i=1985;
  30. };
  31. };
  32. $mwords="";
  33. $words=array_reverse($words);
  34. for ($i=0; $i<count($words); $i++) {
  35. $mwords=$mwords.$words[$i];
  36. if ($i!=count($words)-1) {$mwords=$mwords." ";} else {$mwords=$mwords.$theend;};
  37. };
  38. } else {$mwords=$stranb;};
  39. return $mwords;
  40. }
  41. }
  42.  
  43. $subclass = new substr;
  44.  
  45.  
  46. ?>