How to replace position of string in php?
<pre><code>$text = "abc def ghi abc def ghi abc def ghi abc"
$search = "abc";
$regex = '/(\s)'.$search.'(\s)/i';
$array_key = array();
if(preg_match_all($regex, $text, $tmp)) {
    $array_key = $tmp[0];
    $n = count($tmp[0]);
    for($i=0; $i&lt;$n; $i++) {
        if($n % 2 == 0) {
            $content = str_replace($array_key[$i], 'ABC', $text);
        }
} 
</code></pre>

<p>When i echo $content is output:</p>

<p>"<code>ABC def ghi ABC def ghi ABC def ghi ABC</code>"</p>

<p>But i want result is "<code>ABC def ghi abc def ghi ABC def ghi abc</code>" because <code>$n % 2 == 0</code>, How to fix it ?</p>
