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
https://forums.phpfreaks.com/topic/254618-youtube-bbc/
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
https://forums.phpfreaks.com/topic/254618-youtube-bbc/#findComment-1305655
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.