#42: Converting Plaintext into HTML-Ready Markup

One annoying web aspect of programming is that HTML and plaintext aren't compatible, yet they are frequently used interchangeably. People type things into text areas of forms in plaintext, but chances are pretty good you want to display them in HTML.

Here's an example of something that you might find on a form:

Hey folks,
I recently had my brain removed as a part of my therapy. I am fine, and I can now enjoy Pauly Shore movies with my friends.
Sincerely,
Fred

Because there are no <BR /> or <P> tags in the markup for line breaks, it looks like this when pumped back into a web browser as HTML:

Hey folks, I recently had my brain removed as a part of my therapy. I am fine, and I can now enjoy Pauly Shore movies ...

Get Wicked Cool PHP now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.