title: php surf along html DOM callbacking node plain text contents
body: <p><strong>Scenario</strong>:</p>
  
  <p>I need to apply a php function to the plain text contained inside HTML tags, and show the result, maintaining the original tags (with their original attributes).</p>
  
  <p><strong>Visualize</strong>:</p>
  
  <p>Take this:</p>
  
  <pre><code>&lt;p&gt;Some text here pointing to the &lt;a href="#"&gt;moon&lt;/a&gt; and that's it&lt;/p&gt;
  </code></pre>
  
  <p>Return this:</p>
  
  <pre><code>&lt;p&gt;
  phpFunction('Some text here pointing to the ')
  &lt;a href="#"&gt;phpFunction('moon')&lt;/a&gt;
  phpFunction(' and that\'s it')
  &lt;/p&gt;
  </code></pre>
  
  <p><strong>What I should do</strong>:</p>
  
  <p>Use a PHP html parser (instead of using regexp) and iterate over every tag, applying the callback to the node text content.</p>
  
  <p><strong>Problem</strong>:</p>
  
  <p>If I have, for example, an <code>&lt;a&gt;</code> tag inside a <code>&lt;p&gt;</code> tag, the text content of the parent <code>&lt;p&gt;</code> tag would consist of two different plain text parts, which the php callback should considerate as separate.</p>
  
  <p><strong>Question</strong>:</p>
  
  <p>How should I approach this in a clean and smooth way?</p>
  
  <p>Thanks for your time, all the best.</p>