cut string without partial words (unicode version with mb_substr)


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.