- preg_replace: documentation ( source)
<?php
$subject = <<<'STR'
$array = ['bananna', 'cranberry', 'apple'];
$fn = function ($a, $b) {
if(strlen($a) > strlen($b)) {
return 1;
}
return 0;
};
usort($array, $fn);
STR;
$pattern = '%\'\w*\'%';
$replacement = 'Chocolate';
$newStory = preg_replace($pattern, $replacement, $subject);
print($newStory);