BB Code interpreter for youtube videos
This is just a simple function convert youtube video links or video IDs to the video embed code using BB codes.
You can pass arguments to the BB code or you can disable them.
You can completely omit the value if it is “on”. “nocookie” means the same as “nocookie=on”
[youtube showinfo=off]https://www.youtube.com/watch?v=tH2TvzgFCU0[/youtube]
[youtube]https://youtube.com/watch?v=tH2TvzgFCU0[/youtube]
[youtube]http://www.youtube.com/watch?v=tH2TvzgFCU0[/youtube]
[youtube]//www.youtube.com/watch?v=tH2TvzgFCU0[/youtube]
[youtube]https://youtu.be/tH2TvzgFCU0[/youtube]
[youtube]http://youtu.be/tH2TvzgFCU0[/youtube]
[youtube]//youtu.be/tH2TvzgFCU0[/youtube]
[youtube suggestions=off]tH2TvzgFCU0[/youtube]
[youtube width=350 height=300 nocookie controls=off]tH2TvzgFCU0[/youtube]
<?php
use Rimelek\YBB;
$text = '... Here is your text containing bb codes like: [youtube width=350 height=300 nocookie controls=off]tH2TvzgFCU0[/youtube] ... ';
echo YBB\ybb($text);
echo YBB\ybb($text, ['nocookie' => 'on']);
echo YBB\ybb($text, ['nocookie' => 'on'], ['width', 'height']);
Instead of “on”, you can always write “yes”, “1”, or “true”
Instead of “off”, you can always write “no”, “0” or “false”
Run demo.php for a working demo.