OK, this seems to work:
Code:
<?php
$display = 'hello word - hello word - hello word';
global $find, $replace;
$find = 'h';
$replace = array('1','2','3','4');
$output = preg_replace_callback("/$find/", create_function(
'$matches',
'global $find, $replace; return $matches[0] . $replace[array_rand($replace)];'
),
$display
);
echo $output;
It selects from the $replace array at random but there's nothing stopping it from repeating (you didn't say if you wanted to use them all in random order or if repeating was OK).
Edit: here's another version that's not random but uses all the values (like what you originally posted):
Code:
<?php
$display = 'hello word - hello word - hello word';
$find = 'h';
$replace = array('1','2','3','4');
$rptr = 0;
$output = preg_replace_callback("/$find/", create_function(
'$matches',
'global $find, $replace, $rptr; $ret = $matches[0] . $replace[$rptr]; $rptr = ($rptr + 1) % count($replace); return $ret;'
),
$display
);
echo $output;