You want to turn plain text into reasonably formatted HTML.
First, encode entities with htmlentities( ). Then, transform the text into various HTML structures. The pc_text2html( ) function shown in Example 13-49 has basic transformations for links and paragraph breaks.
The more you know about what the plain text looks like, the better your HTML conversion can be. For example, if emphasis is indicated with *asterisks* or /slashes/ around words, you can add rules that take care of that, as shown in Example 13-50.
More text-to-HTML rules
13.12.4. See Also
Documentation on preg_replace( ) at http://www.php.net/preg_replace.