note 51753 added to function.ereg-replace

From: Date: Sat, 09 Apr 2005 21:50:50 +0000
Subject: note 51753 added to function.ereg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-87771@lists.php.net to get a copy of this message
Sometimes, you would like to match both styles of URL links that are common in chat windows: http://www.yahoo.com www.yahoo.com You can do this by using the following code: <?php function hyperlink(&$text) { // match protocol://address/path/ $text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\">\\0</a>", $text); // match www.something $text = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text); } ?> You can use this function like this: <?php $line = "Check the links: www.yahoo.com http://www.php.net"; hyperlink($line); // Now, all text that looks like a link becomes a link ?> ---- Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51753 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51753&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51753&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51753&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51753&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51753&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51753&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87771) next »