title: str_replace within certain html tags only
body: <p>I have an html page loaded into a PHP variable and am using str_replace to change certain words with other words. The only problem is that if one of these words appears in an important peice of code then the whole thing falls to bits.</p>
  
  <p>Is there any way to only apply the str_replace function to certain html tags? Particularly: p,h1,h2,h3,h4,h5</p>
  
  <p>EDIT:</p>
  
  <p>The bit of code that matters:</p>
  
  <pre><code> $yay = str_ireplace($find, $replace , $html); 
  </code></pre>
  
  <p>cheers and thanks in advance for any answers.</p>
  
  <p><strong>EDIT - FURTHER CLARIFICATION:</strong></p>
  
  <p>$find and $replace are arrays containing words to be found and replaced (respectively). $html is the string containing all the html code.</p>
  
  <p>a good example of it falling to bits would be if I were to find and replace a word that occured in e.g. the domain name. So if I wanted to replace the word 'hat' with 'cheese'. Any occurance of an absolute path like</p>
  
  <p>www.worldofhat.com/images/monkey.jpg
  would be replaced with:
  www.worldofcheese.com/images/monkey.jpg</p>
  
  <p>So if the replacements could only occur in certain tags, this could be avoided. </p>