RobertP Posted January 8, 2012 Share Posted January 8, 2012 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 More sharing options...
abareplace Posted January 9, 2012 Share Posted January 9, 2012 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 More sharing options...
RobertP Posted January 9, 2012 Author Share Posted January 9, 2012 working like a charm, thank you so much! Link to comment https://forums.phpfreaks.com/topic/254618-youtube-bbc/#findComment-1305857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.