title: Is this a bug of php? How would you 'patch' it?
body: <p>I'm dealing with this simple script in <strong>php</strong> :</p>
  
  <pre><code>$a = array('la','co');
  foreach ($a as $unboldeda){
      $boldeda[] = '&lt;b style="color: teal;"&gt;'.$unboldeda.'&lt;/b&gt;';
  }
  $c = 'land of copper';
  echo '&lt;a href="#"&gt;'.str_replace($a, $boldeda, $d=$c).'&lt;/a&gt;';
  </code></pre>
  
  <p>It should result into
   <strong>la</strong>nd of <strong>co</strong>pper</p>
  
  <p>but it results into:</p>
  
  <p><strong>co</strong>lor: teal;">land of <strong>co</strong>pper</p>
  
  <p>bacause <code>str_replace()</code> not only replaces the value of $d, but of $c as well, hence in the second iteration $c will also contain html tags. In my view this doesn't make much sense for a programming language. How would you work around this?</p>