Posted By

shin on 09/29/12


Tagged

substr functions wp description


Versions (?)

cut string without partial words (unicode version with mb_substr)


 / Published in: PHP
 

cut string without partial words (unicode version with mb_substr). for this snippet: http://snipplr.com/view/67385/show-subcategories-with-picture-and-description/

  1. function descr_excerpt($string, $width)
  2. {
  3. $your_desired_width = $width;
  4. $string = mb_substr($string, 0, $your_desired_width+1);
  5.  
  6. if (strlen($string) > $your_desired_width)
  7. {
  8. $string = wordwrap($string, $your_desired_width);
  9. $i = strpos($string, "\n");
  10. if ($i) {
  11. $string = mb_substr($string, 0, $i);
  12. }
  13. }
  14. return $string;
  15. }

Report this snippet  

You need to login to post a comment.