Jump to content

jamiecarter

New Members
  • Posts

    4
  • Joined

  • Last visited

jamiecarter's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. One final question - promise! Why will the above code not work in PHP 5.3, its fine in 5.4 and above? Thanks
  2. Wow. Great much appreciated!
  3. Jacques1 - thank you very much for the reply - it has really helped. In the Replace function, the line $text = $this->render($text[1]); is confusing me, does this "recall" the Render function?? If I had to add a second parameter to Render, how would I pass it into the callback? Thanks
  4. 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;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.