I take user input on my website and I allow formatting through a WYSIWYG editor.
Now I run the entire post I get in PHP through htmlspecialchars with ENT_quotes.
From there I would like to run a regex to convert my allowed rules back to real html.
So that
<p>TEXT</p>
Thanks!
becomes
<p>TEXT</p>
Is there way to do this with regex? I am not familair with it. But basically look for the escaped tags and replace them with real tags, while keeping everything in the middle?
Edit: I want the regex to make the valid HTML codes. First I run the entire thing through htmlspecialchars
to be 100% secure and get entities version of all < & > characters. Then I want a regex to convert ONLY the tags I want back to normal. I do not want to decode all entities back to their regular, I only want to decode the tags I want. so for example a regex search for <p>TEXT</p>
back to <p>TEXT</p>
- I don't want to reconvert just the <
, &
, >
themselves. I want to reconvert only the tags I want. Which in this example is the paragraph tags.