Hi,

I've got a problem which has been driving me bonkers for hours and I just can't seem to work out how to resolve it.

The problem I'm having is trying to search through a string of text (which is actually decoded HTML) looking for content within a <pre> tag and replacing any < > characters found within the <pre> tag and encoding them for display.

So for example I have the following string of text...

Code HTML4Strict:
&lt;p class=&quot;intro&quot;&gt;intro text&lt;/p&gt;
&lt;p&gt;paragraph&lt;/p&gt;
&lt;pre&gt;
var test = {
    init: function()
    {
        document.write(&quot;hello&quot;);
    }
}
&lt;/pre&gt;
&lt;p&gt;more text&lt;/p&gt;
&lt;pre&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    alert(123);
&lt;/script&gt;
&lt;/pre&gt;

...which I then decode using the PHP function html_entity_decode() so it is then displayed in the source code of my page as...

Code HTML4Strict:
<p class="intro">intro text</p> <p>paragraph</p> <pre> var test = { init: function() { document.write("hello"); } } </pre> <p>more text</p> <pre> <script type="text/javascript"> alert(123); </script> </pre>

BUT the problem is I have a Script tag that I want to display as part of a code snippet, but obviously when I encode the string using html_entity_decode() the Script tag is actually executed instead and the code alert(123); is run!

How do I get around this.

I've tried using Regular Expressions to locate the content within the <PRE> tags but the PHP functions for replacing this and placing it back into the complete string of text is just confusing the hell out of me!

Also worth noting that some of these <PRE> tags will have the following HTML within in that that shouldn't be touched...

Code HTML4Strict:
<strong class='keyword'>test</strong>


I really need someone to show me how to go about doing this as I'm getting very confused

Thanks to anyone who can help!

M.