Funzione per tegliare il testo


SUBMITTED BY: Guest

DATE: Sept. 6, 2013, 12:05 p.m.

FORMAT: PHP

SIZE: 795 Bytes

HITS: 927

  1. <?php
  2. ////////////////////////////////////////
  3. //* FUNZIONI PER MANIPOLARE IL TESTO *//
  4. ////////////////////////////////////////
  5. function trimBody($theText, $lmt=100, $s_chr="\n", $s_cnt=2) {
  6. $pos = 0;
  7. $trimmed = FALSE;
  8. for ($i = 1; $i <= $s_cnt; $i++) {
  9. if ($tmp = strpos($theText, $s_chr, $pos+1)) {
  10. $pos = $tmp;
  11. $trimmed = TRUE;
  12. } else {
  13. $pos = strlen($theText) - 1;
  14. $trimmed = FALSE;
  15. break;
  16. }
  17. }
  18. $theText = substr($theText, 0, $pos);
  19. if (strlen($theText) > $lmt) {
  20. $theText = substr($theText, 0, $lmt);
  21. $theText = substr($theText, 0, strrpos($theText,' '));
  22. $trimmed = TRUE;
  23. }
  24. if ($trimmed) $theText .= '...';
  25. return $theText;
  26. }
  27. ?>

comments powered by Disqus