You can do this:
- search with regex for
[\[(.*)\]]
$replace = include_once($matched_string);
- replace
[\[(.*)\]] with $replace
Hmm?
Maybe this could also work:
$string = preg_replace_callback(
'/\[(.*)\]/',
function($matches) {
ob_start();
include $matches[1].'.php';
return ob_get_clean();
},
$string
);
EDIT: I saw this approach within a few "home made" CMS but instead of includeing files they all called a class or function. It could be extended with parameters like Hey, check out this new gallery: [gallery, 15, 200, 200].
You parse that string and find out that You have to call object $gallery, probably a method view with the parameters 15, 200, 200 that will be how many images to show per page and the image thumbnail resolution... So You will call $gallery->view(15, 200, 200);.
In this case the above PHP code will be extended to:
$string = preg_replace_callback(
'/\[(.*)\]/',
function($matches) {
$params = explode(', ', $matches[1]); // by this we get an array with object name and all the parameters
$object = array_shift($params);
return ${$object}->view($params); // for simplicity we pass parameters as an array
},
$string
);
Is this what You want to achieve?