Giddy Rob Posted May 2, 2011 Share Posted May 2, 2011 Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Quote Link to comment https://forums.phpfreaks.com/topic/235331-find-and-replace-with-lt-and-gt-within-code-tags/ Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 You'll first need to find all the <code></code> blocks with preg_match_all using regex. Then use htmlentities to display the code as readable text Quote Link to comment https://forums.phpfreaks.com/topic/235331-find-and-replace-with-lt-and-gt-within-code-tags/#findComment-1209382 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 Having your code blocks be delimitted with is just a disaster waiting to happen. This is why people usually use bbcode conventions. Quote Link to comment https://forums.phpfreaks.com/topic/235331-find-and-replace-with-lt-and-gt-within-code-tags/#findComment-1209781 Share on other sites More sharing options...
Giddy Rob Posted May 3, 2011 Author Share Posted May 3, 2011 Thanks guys, yeah, kinda figured that out just after i posted this. Seems to work ok if you use a textarea to show the code. Just styled it so it doesnt look like one. Any problems doing it this way? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/235331-find-and-replace-with-lt-and-gt-within-code-tags/#findComment-1209878 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 You want to take all the code inside the textarea and run it through htmlentities. Otherwise, it's a good solution. Quote Link to comment https://forums.phpfreaks.com/topic/235331-find-and-replace-with-lt-and-gt-within-code-tags/#findComment-1210004 Share on other sites More sharing options...
Giddy Rob Posted May 3, 2011 Author Share Posted May 3, 2011 sweet....will do. Cheers mate Quote Link to comment https://forums.phpfreaks.com/topic/235331-find-and-replace-with-lt-and-gt-within-code-tags/#findComment-1210036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.