How to escape code in <code> tag with php htmlentities, even if tag has attributes
<p>So someone actually posted a fantastic solution here <a href="https://stackoverflow.com/questions/9509447/how-can-i-escape-all-code-within-code-code-tags-to-allow-people-to-post-code">How can I escape all code within &lt;code&gt;&lt;/code&gt; tags to allow people to post code?</a></p>

<p>The problem is that this only works if it's <code>&lt;code&gt;&lt;/code&gt;</code>. However, this breaks with <code>&lt;code id="lol"&gt;&lt;/code</code> for example, since it contains an attribute. How can I account for this, in order to strictly escape strings inside the code tag, whether or not it has any attributes.</p>

<p>I apologize if there is an obvious solution to this. Regexes give me nightmares.</p>

<p><strong>Edit</strong></p>

<p>As I explained in the question initially, the post that is supposedly a duplicate does not account for the <code>&lt;code&gt;</code> tag with something like a class or any other attributes.</p>