I'm trying to make a whitelist of html tags, here's my code :
$string = "<x>-<x>";
$result = preg_match('#^<(?!white1|white2)>.*<(\1)>$#i', $string);
But it returns false, and I don't know why. I simplified the regex to avoid confusions, but this is still the same idea.
I want to match every correct tag but the ones I want to keep safe. This regex will go on a preg_replace to erase every matched tag and let the ones I allow.
Thanks for your help in advance !
EDIT: If I find a way to do this with regexs, I'll put the solution here. But for now, I'll do it with strip_tags()
.
EDIT2: The easiest way I thought to is to parse all the tags and then revert back the ones we allow.