note 37824 deleted from function.preg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 18 Jun 2006 13:16:21 +0000 |
| Subject: | note 37824 deleted from function.preg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114298@lists.php.net to get a copy of this message | ||
Note Submitter: syd_egan at hotmail dot com
----
I have been working to improve the expressions to turn text urls into html hyperlinks, and eliminate
the problem with very long urls causing formatting problems, without resorting to a link called
"link".
I have written an expression to display only the host name whilst linking to the full url:
$text = preg_replace( "
(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?i",
"<a href=\"\\0\" target=\"_blank\">\\4</a>", $text);
Thus:
"More info can be found at http://www.php.net/manual/en/function.preg-match-all.php"
will become
"More info can be found at
<a href="http://www.php.net/manual/en/function.preg-match-all.php">
www.php.net</a>"
Hope this saves someone else re-inventing this wheel!!