Wednesday, January 23, 2008

keeping line feeds in textarea from HTML to RTF

Hope this helps someone not named Shawn.

I want to keep the formatting when a user hits the "enter" key inside a textarea on a form. My problem is further deepened by the fact that I don't just return the results straight back to a HTML page. My results get merged with a rtf file that then gets emailed to someone who can open the file using Word.

I found this site which gives the RTF v1.5 documentation, and from this gleaned that the \par denotes a new paragraph. Yea!

I then just did a string replace (using PHP) and searched through the user submitted textarea to replace all occurrences of chr(10) with "\par " - don't forget the space.

I now have line breaks in the final RTF. And a happy customer.

<the todd />