Page 1 of 1

fixed 72 character width formatting

Posted: Sun Sep 21, 2003 1:19 am
by Haneda
Hello, I am having a tough time wrapping my head around some code i need to write.

Given a string of many lines, \r seperated, I need to do some specific truncating of the lines.

if the 72nd character is a space, replace that with a \r, if it is not a space, step backwards in the string untill you hit a space and replace with a \r.

Basically, I have a raw email body, and it is not wrapped in any way, I need it to be wrapped at 72 characters.

If there are perl libs, functions, and other tools used to deal with this, I wont be able to use them, I need to do this with plain normal php functions.

thanks

Posted: Sun Sep 21, 2003 4:17 am
by pootergeist
$str = wordwrap($str, 75, '\n\r');

Posted: Sun Sep 21, 2003 5:09 am
by Haneda
OK, lets try this without using wordwrap(), I have to also port this to another language and will not have that ability.