/ Published in: PHP
Cut PHP strings at full word breaks.
Expand |
Embed | Plain Text
/* usage: $string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; $length = 3; echo implode(' ',array_slice(explode(' ', $string),0,$length)); */
Comments
Subscribe to comments
You need to login to post a comment.

If you´re having trouble with Special Chars try using "explode" to seperate the words: implode(' ',array_slice(explode(' ',$string),0,$length));
Thanks vitruvo! I actually discovered that issue too - I'm updating the code.