Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class testWork
- {
- public function task_10($str)
- {
- if (!is_string($str))
- throw new InvalidArgumentException('Argument must be String. Input was: ' . $str);
- echo preg_replace_callback(
- "#\{(.+?)\}#is",
- [$this, 'callback'],
- $str);
- }
- public function callback($matches)
- {
- $result = explode('|', $matches[1]);
- return $result[rand(0,2)];
- }
- }
- $str = '{Я помню|Не помню|Какое} чудное {мгновенье|затменье|творенье}';
- $obj = new testWork();
- $obj->task_10($str);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement