<?php
function text2func($text) { // board code with function task
preg_match_all('/\[(.*)](.*)\[\/(.*)]/', $text, $outputs, PREG_SET_ORDER);
foreach ($outputs as $out) {
$values = explode(',', $out[2]);
$text = str_replace('['. $out[1] .']'. $out[2] .'[/'. $out[3] .']', call_user_func_array($out[1],$values), $text);
}
return nl2br($text);
}
// Using
function exampleFunction ($value) {
return "real";
}
function exampleFunction2 ($url, $alt, $width) {
return "<img src='". $url ."' alt='$alt' width='$width'>";
}
$text = "Lorem Ipsum is simply [exampleFunction]dummy[/exampleFunction] text of the printing and typesetting industry.
[exampleFunction2]/exampleImageURL.jpg,explanation text,200[/exampleFunction2]";
echo text2func($text);