📅  最后修改于: 2022-03-11 14:54:33.550000             🧑  作者: Mango
i searched for a while for a script, that could see the difference between an html tag and just < and > placed in the text,
the reason is that i recieve text from a database,
wich is inserted by an html form, and contains text and html tags,
the text can contain < and >, so does the tags,
with htmlspecialchars you can validate your text to XHTML,
but you'll also change the tags, like to ,
so i needed a script that could see the difference between those two...
but i couldn't find one so i made my own one,
i havent fully tested it, but the parts i tested worked perfect!
just for people that were searching for something like this,
it may looks big, could be done easier, but it works for me, so im happy.
/i";
$replacement = "<$1$2$3$4$5$6$7$8$9$10>";
$text = preg_replace($tags, $replacement, $text);
$text = preg_replace("/=\"\"/", "=", $text);
return $text;
}
?>
an example:
this is greater > than this
this is the same = as this
This is a link
Bold italic etc...";
echo fixtags($string);
?>
will echo:
this is smaller < than this
this is greater > than this
this is the same = as this
This is a link
Bold italic etc...
I hope its helpfull!!