note 37824 modified in function.preg-replace by didou
| From: | didou@php.net | Date: | Mon, 10 Jan 2005 03:24:14 +0000 |
| Subject: | note 37824 modified in function.preg-replace by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83028@lists.php.net to get a copy of this message | ||
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!!
--was--
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:
$txt = preg_replace( "/(http|ftp)+(s)?:(\\/\\/)((\\w|\\.)+)(\\/)?(\\S+)?/i", "<a
href=\\"\\\\0\\">\\\\4</a>", $txt );
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!!
http://php.net/manual/en/function.preg-replace.php