title: How to parse HTML using PHP and display as plain text all tags within <code></code> except <br> tag
body: <p>I have a problem to solve but I'm not able to do it, then I beg for your help!
  In fact, it's all about a blog posting form. When they publish their articles, the post blog is converted by htmlentities an stored in the DB.</p>
  <pre><code>htmlentities(ucfirst($var), ENT_QUOTES, 'utf-8');
  </code></pre>
  <p>When it comes to display the text, they use the function html_entity_decode.</p>
  <pre><code>$var = html_entity_decode($var, ENT_QUOTES, 'UTF-8');
  </code></pre>
  <p>Now I want to be able to display tags within html tag &lt; code &gt; regardless the programming language used (PHP, HTML, Java, Javascript, ...).</p>
  <p>For example I have the following code:</p>
  <pre><code>&lt;?php
  
  $html = &lt;&lt;&lt;EOD
      &lt;h1&gt;Escape HTML or Other Programming tags&lt;/h1&gt;
      &lt;p&gt;This must be rendered without any problem&lt;/p&gt;
      &lt;p&gt;
      &lt;code style=&quot;display:block;background:rgb(230,230,230);padding:2%&quot;&gt;
          &lt;h4&gt;Show this title in HTML&lt;/h4&gt;
          &lt;p&gt;This paragraph must be in &lt;strong&gt;HTML&lt;/strong&gt; and this &lt;a href=&quot;&quot;&gt;Link&lt;/a&gt; too !&lt;/p&gt;
          &lt;?php 
              echo &quot;Display this PHP code!&quot;;
          ?&gt;
          &lt;script&gt;
              alert(&quot;Don't pop-up please!&quot;);
          &lt;/script&gt;
      &lt;/code&gt;
      &lt;a href=&quot;&quot;&gt;Link rendered&lt;/a&gt;
      &lt;/p&gt; 
      EOD;
  </code></pre>
  <p>Look at this image to see what I want as output:
  <a href="https://i.stack.imgur.com/AsN9F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AsN9F.png" alt="show tags within HTML code tag as plain text" /></a></p>
  <p><strong>As you can see, all tags are displayed as plain text except &lt; br &gt; tag</strong></p>
  <p>My thoughts:<br/>
  I guess I have to parse this HTML code to find code tags and then convert codes within that tag in plain text, but I'm not sure to know how to this correctly.</p>
  <pre><code>$dom = new DOMDocument; 
  $dom-&gt;loadHTML($html);
  $xpath = new DOMXPath($dom);
  foreach ($xpath-&gt;query(&quot;//code&quot;) as $node) {
      $node = htmlspecialchars($node-&gt;nodeValue);
  }
  $texte = $dom-&gt;saveHTML();
  echo $texte;
  </code></pre>
  <p>Can you please help me to achieve my objective?</p>