note 37824 added to function.preg-replace

From: Date: Fri, 28 Nov 2003 15:10:00 +0000
Subject: note 37824 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-61077@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: $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!! ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37824 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37824&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37824&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61077) next »