fixed 72 character width formatting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Haneda
Forum Newbie
Posts: 2
Joined: Sun Sep 21, 2003 1:19 am

fixed 72 character width formatting

Post 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
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

$str = wordwrap($str, 75, '\n\r');
Haneda
Forum Newbie
Posts: 2
Joined: Sun Sep 21, 2003 1:19 am

Post by Haneda »

OK, lets try this without using wordwrap(), I have to also port this to another language and will not have that ability.
Post Reply