RegExp (preg) - how to split long string to length,without cutting words

From: Date: Fri, 16 Apr 2004 10:47:09 +0000
Subject: RegExp (preg) - how to split long string to length,without cutting words
Groups: php.general 
Request: Send a blank email to php-general+get-183601@lists.php.net to get a copy of this message
Hi, I am a RegExp newbie, and need help with this: i have a long string (500 / 600 chars), and need to split it in lines. Each line has a maximum length (20), and words in the line shouldn't be cut, instead the line should end at the end of the word whose last char position is <= 20. the effect is like a left align in a word processor, where lines wrap at 20, and the words are not cut. example: string= "aaaaa bbbbb ccccc ddddd eeeee ffffffffff ggggg"
(char)            1111111111222222222233333333334444444
         1234567890123456789012345678901234567890123456
regexp should output: "aaaaa bbbbb ccccc ddddd eeeee ffffffffff ggggg" Is it a sensible thing to do this job with regExp or is it better to use the usual string functions? Thanx moondog

« previous php.general (#183601) next »