Extract urls in text

Laurafulk

New Member
Let say we've text with more than one url within, so i would like to extract that url and doing some changes then shows up the text.Here is the code i'm using\[code\]<?PHP$text = "This is text with links http://google.com and www.yahoo.com";$text = ereg_replace( "www\.", "http://www.", $text );$text = ereg_replace( "http://http://www\.", "http://www.", $text );$text = ereg_replace( "https://http://www\.", "https://www.", $text );$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";if(preg_match($reg_exUrl, $text, $url)) {$text = preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $text);echo $text;}else{echo "NO URLS";}?>\[/code\]The problem// output source (repeat for first link)\[code\]This is text with links <a href="http://google.com" rel="nofollow">http://google.com</a> and <a href="http://google.com" rel="nofollow">http://google.com</a>\[/code\]It depends on array so it only takes the first URL \[code\]$url[0]\[/code\] so how can i apply for all links to be found within the text ~ Thanks
 
Back
Top