Guys, total PHP noob here but years of MS development experience (I know, I know,,,).
Really need to get an understanding of this code, I have a handle on the individual lines and can run the code, but overall I'm kinda at a loss, all help much appreciated!
class MyTestClass
{
const REGEXP = '/\{(((?>[^\{\}]+)|(?R))*)\}/x';
public function render($text)
{
return preg_replace_callback(
self::REGEXP,
[$this, 'replace'],
$text
);
}
public function replace($text)
{
$text = $this->render($text[1]);
$parts = explode('|', $text);
return trim($parts[array_rand($parts)]);
}
}
$obj = new MyTestClass();
$result = $obj->replace("Fred");
echo $result;