Super-short PHP Word Limiter


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

Cut PHP strings at full word breaks.


Copy this code and paste it in your HTML
  1. implode(' ',array_slice(explode(' ', $string),0,$length));
  2.  
  3. /* usage:
  4. $string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
  5. $length = 3;
  6. echo implode(' ',array_slice(explode(' ', $string),0,$length));
  7. */

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.