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 />'; Quote Link to comment 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"; ?> Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.