note 90728 deleted from function.ereg-replace by danbrown

From: Date: Wed, 06 May 2009 16:20:58 +0000
Subject: note 90728 deleted from function.ereg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154286@lists.php.net to get a copy of this message
Note Submitter: az-lion at mail dot ru ---- <?php class hyperlink { var $text; function make($text,$target) { if (!$target or !$target == "_blank" or !target == "_self" or !$target == "_parent" or !$target == "_top") { $target = "_blank"; } // match protocol://address/path/ $text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\" target=\"$target\">\\0</a>", $text); // match www.something $text = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\" target=\"$target\">\\2</a>", $text); // return $text return $text; } } $hyperlink = new hyperlink; $text = "www.combats.ge"; echo $hyperlink->make($text,"_blank"); echo "<br>"; $text = "http://www.combats.ge"; echo $hyperlink->make($text,"_blank"); ?>

« previous php.notes (#154286) next »