Jump to content

PHP preg_replace

TwistedDictator

Is it possible to use pre_replace to use on urls? Currently I am trying to get a youtube video and change replace it with the code link , for example using preg_replace:

www.youtube.com/watch?v=6Zgp_G5o6Oc

and changing it to

www.youtube.com/watch?v=6Zgp_G5o6Oc 

Would love the help

Slick:

I don't care if you are right or wrong... someone will come around and correct you if you are wrong. What people need to realize is that we need to step up as a community and get above the pathetic fights and bickering. Share knowledge, be friendly, enjoy your stay.

He also forgot to mention if you dont know about the topic then dont make stuff up. Dont claim fake or assume things just by reading the title, Read the post. It doesnt matter if you made 3,000 as it could be mostly crap...

Link to comment
Share on other sites

Link to post
Share on other sites

what's your input? i imagine you have a long string (e.g. a forum post) and you want to make all youtube references into clickable links?

Link to comment
Share on other sites

Link to post
Share on other sites

This should do the trick :) (it can also take the youtu.be links)

$content = "www.youtube.com/watch?v=6Zgp_G5o6Oc";$content = preg_replace_callback('/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-]+)(&(amp;)?[\w\?=]*)?/', function($matches){ return "[video]{$matches[0]}[/video]"; }, $content);
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×