Change url to html link

<?php

$str = 'My post with links http://hyperspatial.com in it';
preg_replace('!((?:www|http://)[^r ]+)!', '<a href="1">1</a>', $str);

 

//Here is another method
function addhttp($url) {     if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {         $url = "http://" . $url;     }     return $url; }
?>

0 Comments

You must be logged in to post a comment.