note 41245 added to function.wordwrap
| From: | tvoipio at cc dot hut dot fi | Date: | Sun, 04 Apr 2004 04:52:14 +0000 |
| Subject: | note 41245 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67603@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41245
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41245&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41245&report=yes
Search -- http://master.php.net/manage/user-notes.php