note 41245 deleted from function.wordwrap by nlopess

From: Date: Sun, 04 Apr 2004 11:07:50 +0000
Subject: note 41245 deleted from function.wordwrap by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-67619@lists.php.net to get a copy of this message
Note Submitter: tvoipio@cc.hut.fi ---- If you use this wordwrap(), then notice that because it doesn't care about the content format, you want to use it before adding any markup or preferably even before turning html special characters into entities. I'm personally happy with this function as I simply want plain text to put into a <pre> box. What I do is: <?php /* Simple message formatter */ function format_message($message) { $message = wordwrap($message, 80); $message = htmlspecialchars($message); $message = preg_replace( '/(https?|ftp):\/\/[^ \n\r\t\"]+/', '<a href="\0">\0</a>', $message); $message = preg_replace( '/[^ \n\r\t\"]+@[^ \n\r\t\"]+/', '<a href="mailto:\0">\0</a>', $message); return "<pre>\n$message\n</pre>"; } ?> This nicely wraps text to 80 characters, then replaces html special characters, then turns http/https/ftp urls and mail-addresses into links, and finally wraps it into a <pre> box.

« previous php.notes (#67619) next »