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? :)

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.