I am trying to create a script that will help me convert urls provided by users in their blog posts of PM to other users into a real clickable links , The script i created is working fine except that it is not converting after the 2nd link occurred in the post , I hope someone can help me with that.
Here is the code :
$text="Click [link]http://www.google.com.eg[/link] or click [link]http://www.yahoo.com[/link] or click [link]http://www.hotmail.com[/link]";
preg_match_all('/\\[link](.*?)\\[\/link]/s', $text, $links);
$link_count=count($links);
for($i=0;$i<$link_count;$i++){
$link_url=preg_replace("/\[link]/", "", $links[0][$i]);
$link_url=preg_replace("/\[\/link]/","",$link_url);
$text=str_replace($links[0][$i],"<a href=\"" . $link_url . "\">" . $link_url . "</a>",$text);
}
echo $text;