Re: RegExp (preg) - how to split long string to length,wit
| From: | moondog | Date: | Fri, 16 Apr 2004 11:23:28 +0000 |
| Subject: | Re: RegExp (preg) - how to split long string to length,wit | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-183603@lists.php.net to get a copy of this message | ||
nice!
(things are often under my nose, still I can't see them...I was using explode and loops...)
thx
moondog
Mike Ford wrote:
On 16 April 2004 11:47, moondog wrote: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"The latter -- "the usual string function" in this case being http://www.php.net/wordwrap. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk(char) 1111111111222222222233333333334444444 1234567890123456789012345678901234567890123456regexp 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?Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211