Posted By

javierarce on 07/18/06


Tagged

php words textmate trim text


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

luman
neverwolf
jkochis
NexusRex
blakeb
hudge
pixelhandler


Trim Text


 / Published in: PHP
 

Devuelve un texto acortado según el parámetro $words introducido.

  1. public function trim_text($text, $words = 50)
  2. {
  3. $matches = preg_split("/\s+/", $text, $words + 1);
  4. $sz = count($matches);
  5. if ($sz > $words)
  6. {
  7. unset($matches[$sz-1]);
  8. return implode(' ',$matches)." ...";
  9. }
  10. return $text;
  11. }

Report this snippet  

You need to login to post a comment.