0

I using this code to change urls to links:

<?php // The Regular Expression filter $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; // The Text you want to filter for urls $text = "The text you want to filter goes here. http://google.com http://www.ynet.co.il"; // Check if there is a url in the text if(preg_match($reg_exUrl, $text, $url)) { // make the urls hyper links echo preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $text); } else { // if no urls in the text just return the text echo $text; } ?> 

But every link direct to the first link How can I make foreach that will solve it?

Thanks.

Haim

2
  • What do you mean by "URL" and "link"? Commented May 7, 2014 at 16:00
  • Its mean the I make this text "Hello google.com" to "Hello <a href="google.com">http://www.google.com</a> Commented May 7, 2014 at 16:01

1 Answer 1

2

Try:

$reg_exUrl = "..."; $text = "..."; echo preg_replace($reg_exUrl, '<a href="$0" rel="nofollow">$0</a>', $text); 

Much simpler ;)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.