- preg_replace_callback: documentation ( source)
<?php
function get_video_block($id) {
return "***replacement text for $id***";
}
function display_video($text) {
return preg_replace_callback(
'/\[VIDEO ID=(\d+)]/',
function($m) {
return get_video_block($m[1]);
},
$text
);
}
echo display_video("Here is a video [VIDEO ID=33] to watch");