- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
<?php
class X {
private function z($matches) {
var_dump($matches);
switch ($matches) {
case 'cool':
return 'wow';
case 'hey':
return 'hehe';
}
}
public function y($template) {
echo preg_replace_callback('/\[\[\s?([^\]]+)\s?\]/', [$this, 'z'], $template);
}
}
$x = new X();
$x->y('bla bla [[ hey ]] dasfasdf [[ cool ]] werwr');