php – preg_replace make links out of http text

To make links inside a text, use the following code:

<?php 
$text = "This is an example text for http://www.google.ro"; 
/*
 * Use only one of the following examples  
 */ 
 // For http|https|ftp|ftps link precedence 
 $text = preg_replace("/(http|https|ftp|ftps)://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(/S*)?/", "<a href=$0>$0</a> ", $text); 
 // For www|ww2 link precedence 
 #$text = preg_replace("/(www|ww2).[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(/S*)?/", "<a href=http://$0>$0</a> ", $text);  

 echo $text; 
?>Code language: HTML, XML (xml)