3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thesaurus { protected $synonyms = array( array('wonderful', 'great', 'amazing', 'fabulous'), array('look', 'see', 'observe') ); public function replace($word) { foreach ($this->synonyms as $synonym) { if (in_array($word, $synonym)) { return $synonym[ array_rand($synonym) ]; } } return $word; } } class Transformer { protected $thesaurus; public function __construct(Thesaurus $thesaurus) { $this->thesaurus = $thesaurus; } public function transform($string) { foreach (str_word_count($string) as $word) { $string = str_replace($word, $thesaurus->replace($word), $string); } return $string; } } $transformer = new Transformer(new Thesaurus); echo $transformer->transform('This is my wonderful description. It really is wonderful. Look how wonderful it is.'), PHP_EOL;

preferences:
29.21 ms | 402 KiB | 5 Q