note 32177 added to function.preg-replace-callback
| From: | dfx at dfx dot at | Date: | Mon, 19 May 2003 18:49:25 +0000 |
| Subject: | note 32177 added to function.preg-replace-callback | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48604@lists.php.net to get a copy of this message | ||
here's how you can turn plain text into html, turning plain urls into hyperlinks:
function urlparse($m) {
$t = $m[0];
if (preg_match(',^\w+://,', $t))
return "<a href=\"$t\">$t</a>";
return "<a href=\"http://$t\">$t</a>";
}
function parseplaintext($d) {
$pd = str_replace("\n", "<br />", htmlspecialchars($d));
$pd = preg_replace_callback(
'°(\w+://([^\s/:@]+(:[^\s/:@]++)?@)?|\bwww\.)' .
'[\w.]+(:\d+)?(/([-\w?&%+#;|@]*[\w-])?)?°is', "urlparse", $pd);
return $pd;
}
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32177
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32177&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32177&report=yes