I’m having trouble with the logic of taking a paragraph of text and splitting it on words/sentences to send out in multiple text messages. Each text message can only have up to 160 characters. I want to cleanly break a paragraph up.
Here is the solution (thanks Leventix!):
public static function splitStringAtWordsUpToCharacterLimit($string, $characterLimit) { return explode("n", wordwrap($string, $characterLimit)); }
Advertisement
Answer
You can use wordwrap, then explode by newlines:
public static function splitStringAtWordsUpToCharacterLimit($string, $characterLimit) { return explode("n", wordwrap($string, $characterLimit)); }