I have a string like this:
Blablabla http://www.soundcloud.com/artist/track
www.facebook.com/page is my page
Try www.youtube.com/watch?v=1234567 for my video
Check http://www.somesite.com/bla.
I would like to replace URLs and insert different wordpress shortcodes inside a user generated post, exchange urls with videos or soundcloud widgets automatically and create regular links from all the other URLs and emails into something like this (simplified):
Blablabla [soundcloud]www.soundcloud.com/artist/track[/soundcloud]
[facebook]www.facebook.com/page[/facebook] is my page
Try [youtube]www.youtube.com/watch?v=1234567[/youtube] for my video
Check [url]www.somesite.com/bla[/url].
So I think I need to run several preg_replace actions on the string.
After I replaced Soundcloud, Facebook and Youtube URLs with the Wordpress shortcodes I need to run a preg_replace on the remaining URLs like http://www.somesite.com/bla but since the Facebook/Soundcloud/Youtube patterns are still available in the string (now inside the shortcodes) they will be replaced again into...
[youtube][url]www.youtube.com/watch?v=1234567[/url][/youtube]
I do not want this behaviour. I should be like this:
[url]www.youtube.com/watch?v=1234567[/url]
This is my basic RegEx:
((https?://)(www.)|(https?://)|(www.))[^ <]+
I need to replace URLs beginning with http, https and www
Has anyone a solution ?
greetz,
Mat