Php replace 2 characters with 2 other random ones
<p>I want to swap 2 characters in a string with 2 other ones.</p>

<p>Start string = "`bHello `!how `Qare `%you."</p>

<p>Random string = "1234567890abcdefghijklmnopqrstuvwxyz!£$%^&amp;@"</p>

<p>How do i swap `b `! `Q `% with random ones so it looks something like this</p>

<p>End result string = "`4Hello `^how `$are `@you."</p>

<p>I have tried this so far</p>

<p>I tried so far</p>

<p>$out = "`vHow `!are `@you."</p>

<p>$patterns = array("`1","`J","`2","`3","`4","`5","`6","`7","`!","`$","`%","`^","`&amp;","`)","`~","`#","`@","`q","`e","`y","`t","`p","`j","`k","`l","`M","`x","`v","`m","`Q","`E","`R","`T","`Y","`P","`G","`K","`L","`X","`V");</p>

<p>$pretest = array("`1","`J","`2","`3","`4","`5","`6","`7","`!","`$","`%","`^","`&amp;","`)","`~","`#","`@","`q","`e","`y","`t","`p","`j","`k","`l","`M","`x","`v","`m","`Q","`E","`R","`T","`Y","`P","`G","`K","`L","`X","`V");</p>

<p>$tempstr = $pretest[rand(0, strlen($pretest)-1)];</p>

<p>$substs = "`".$tempstr;</p>

<p>$out = preg_replace($patterns, $substs, $out);</p>

<p>However the end result is </p>

<p>$out = "`%How `%are `%you."</p>

<p>it picks only 1 random and changes them all to that one.</p>
