<?php var_dump(bbc2html('[b]stuff[/b][youtube]abc[/youtube]')); function getYoutubeVideoID($id) { // Just a demo function return '!!'.$id.'!!'; } function bbc2html($content) { $search = '/\[(b|u|i)]([^\[]*)\[\/\1]/'; $replace = '<$1>$2</$1>'; $newContent = preg_replace($search, $replace, $content); return preg_replace_callback( '/\[youtube](.*?)\[\/youtube]/', static function ($matches) { return '<div class="video_wrapper card border-0 shadow text-center m-2" style="width: 25rem;"> <div class="video_trigger card-body" data-source="'.getYoutubeVideoID($matches[1]).'" data-type="youtube"> <p class="text-center">As soon as you click on the button you accept that cookies from YouTube to be loaded</p> <input type="button" class="btn btn-success" value="OK"> <a href="$2" type="button" target="_blank" class="btn btn-danger"><i class="fa-brands fa-youtube pe-1"></i>direct link</a> </div> <div class="video_layer" style="display: none;"> <iframe src="" border="0" data-scaling="true" data-format="16:9" style="height: 0px;"></iframe> </div> </div>'; }, $newContent ); }
You have javascript disabled. You will not be able to edit any code.