preg_replace
<?php $text = "This is a link to http://www.java2s.com/."; echo preg_replace("/http:\/\/(.*)\//", "<a href=\"\${0}\">\${0}</a>", $text); ?>