0

Hi all

I've been trying to figure out how I would accomplish my problem mentioned in the titl of this thread with no luck. I've looked at a combination of using strstr, str_replace, substr and strpos.

What I'd like to do is manipulate a paragraph so that if there is a web address in it, it gets an <a> tag wrapped around it with the href pointing to the web address.

Can anyone give me some suggestions please? :)

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Venom Rush
0

you would need to use a regex and the preg_replace function.

here just found this:

$text = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text);

remember google is your friend

0

you would need to use a regex and the preg_replace function.

here just found this:

$text = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text);

remember google is your friend

Thanks for that kkeith29. Could you possibly give me the link to where you found that. There might be cases where the link is without the http:// portion and I can't seem to figure out how to alter the above code.

P.S. Google doesn't love me...because it found out I use Yahoo as well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.