I want to swap 2 characters in a string with 2 other ones.
Start string = "`bHello `!how `Qare `%you."
Random string = "1234567890abcdefghijklmnopqrstuvwxyz!£$%^&@"
How do i swap `b `! `Q `% with random ones so it looks something like this
End result string = "`4Hello `^how `$are `@you."
I have tried this so far
I tried so far
$out = "`vHow `!are `@you."
$patterns = array("`1","`J","`2","`3","`4","`5","`6","`7","`!","`$","`%","`^","`&","`)","`~","`#","`@","`q","`e","`y","`t","`p","`j","`k","`l","`M","`x","`v","`m","`Q","`E","`R","`T","`Y","`P","`G","`K","`L","`X","`V");
$pretest = array("`1","`J","`2","`3","`4","`5","`6","`7","`!","`$","`%","`^","`&","`)","`~","`#","`@","`q","`e","`y","`t","`p","`j","`k","`l","`M","`x","`v","`m","`Q","`E","`R","`T","`Y","`P","`G","`K","`L","`X","`V");
$tempstr = $pretest[rand(0, strlen($pretest)-1)];
$substs = "`".$tempstr;
$out = preg_replace($patterns, $substs, $out);
However the end result is
$out = "`%How `%are `%you."
it picks only 1 random and changes them all to that one.