13.12.1. ProblemYou want to turn plain text into reasonably formatted HTML. 13.12.2. SolutionFirst, 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. pc_text2html( )
13.12.3. DiscussionThe 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 AlsoDocumentation on preg_replace( ) at http://www.php.net/preg_replace. |