Results 1 to 1 of 1
Aug 18, 2009, 13:40 #1
- Join Date
- Sep 2008
- 0 Post(s)
- 0 Thread(s)
Problem trying to replace text using RegExp and PHP functions
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...
...which I then decode using the PHP function html_entity_decode() so it is then displayed in the source code of my page as...
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...
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!