Jump to content

YouTube BBC


RobertP

Recommended Posts

 

I need some help with one of my bbc tags. I can get the first video to work, however i have no idea how to add wild cards, maybe for example instead of

 

it would be

http://de.youtube.com/watch?v=VDvr08sCPOc

or

&feature=related

etc..

 

 

$string = '[youtube]http://www.youtube.com/watch?v=VDvr08sCPOc[/youtube]';
echo 'Normal: <br />'.preg_replace('#([[]youtube[]])http:\/\/www.youtube.com\/watch\?v=(.*)([[]/youtube[]])#e','(\'<iframe width="560" height="315" src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>\')',$string).'<br /><br />';

$string = '[youtube]http://www.youtube.com/watch?v=VDvr08sCPOc&feature=related[/youtube]';
echo 'Issue #1: <br />'.preg_replace('#([[]youtube[]])http:\/\/www.youtube.com\/watch\?v=(.*)([[]/youtube[]])#e','(\'<iframe width="560" height="315" src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>\')',$string).'<br /><br />';

$string = '[youtube]http://www.youtube.com/watch?feature=related&v=VDvr08sCPOc[/youtube]';
echo 'Issue #2: <br />'.preg_replace('#([[]youtube[]])http:\/\/www.youtube.com\/watch\?v=(.*)([[]/youtube[]])#e','(\'<iframe width="560" height="315" src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>\')',$string).'<br /><br />';

 

Link to comment
Share on other sites

Try this:

 

<?php
$regex = '#\\[youtube]http://(?:\\w+\\.)?youtube.com/watch\\?' .
'(?:feature=related&)?v=(\\w*)(?:&feature=related)?\\[/youtube]#';
$repl = '<iframe width="560" height="315" src="http://www.youtube.com/embed/\\1" '.
'frameborder="0" allowfullscreen></iframe>';

$subjects = array('[youtube]http://www.youtube.com/watch?v=VDvr08sCPOc[/youtube]',
'[youtube]http://de.youtube.com/watch?v=VDvr08sCPOc[/youtube]',
'[youtube]http://youtube.com/watch?v=VDvr08sCPOc[/youtube]',
'[youtube]http://youtube.com/watch?v=VDvr08sCPOc&feature=related[/youtube]',
'[youtube]http://youtube.com/watch?feature=related&v=VDvr08sCPOc[/youtube]');
foreach ($subjects as $subj)
echo preg_replace($regex, $repl, $subj) . "<br>\n";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.