random preg replace in an array?
Posted: Fri Jan 23, 2004 9:24 pm
I'm really new at this, but is there a way to randomly pick a line from the array then preg replace it?
For the below string i just want some of the 5 letters from the array to randomly stutter. I don't want all the c,d,e,s,t to preg replace. just randomly any of them.
thanks!
code>>>>>>
$string = "2. The Alphabet Game
Starting with challenge your child to find each letter of the alphabet on signs as you travel. Players call out the letter and the word it's in as they see each one -- the first one to reach wins. Vary the action by limiting the places to find letters to only license plates, road signs, or billboards.";
$tr_list = array(
"/c/" => "c-c-c.....",
"/d/" => "d-d-d....",
"/e/" => "e-e-e....",
"/s/" => "s-s-s....",
"/t/" => "t-t-t...."
);
$random = rand(0,sizeof($tr_list)-1);
//echo $random;
//echo sizeof($tr_list);
//list($a[0], $a[1], $a[2], $a[3], $a[4]) = $tr_list;
//echo $tr_list;
//echo $string;
foreach ($tr_list as $key => $value) {
$translateThis = preg_replace($key, $value, $string);
echo $string;
}
For the below string i just want some of the 5 letters from the array to randomly stutter. I don't want all the c,d,e,s,t to preg replace. just randomly any of them.
thanks!
code>>>>>>
$string = "2. The Alphabet Game
Starting with challenge your child to find each letter of the alphabet on signs as you travel. Players call out the letter and the word it's in as they see each one -- the first one to reach wins. Vary the action by limiting the places to find letters to only license plates, road signs, or billboards.";
$tr_list = array(
"/c/" => "c-c-c.....",
"/d/" => "d-d-d....",
"/e/" => "e-e-e....",
"/s/" => "s-s-s....",
"/t/" => "t-t-t...."
);
$random = rand(0,sizeof($tr_list)-1);
//echo $random;
//echo sizeof($tr_list);
//list($a[0], $a[1], $a[2], $a[3], $a[4]) = $tr_list;
//echo $tr_list;
//echo $string;
foreach ($tr_list as $key => $value) {
$translateThis = preg_replace($key, $value, $string);
echo $string;
}