title: How to replace only the last match of a string with preg_replace?
body: <p>I have to replace the last match of a string (for example the word foo) in HTML document. The problem is that the structure of the HTML document is always random.</p>
  
  <p>I'm trying to accomplish that with preg_replace, but so far I know how to replace only the first match, but not the last one.</p>
  
  <p>Thanks.</p>