Thanks Thomasvdbulk for your workaround, I would like to add a precision:
When the HTML contains a link tag without new line before the script doesn't work :/
Your example:
<?php
$string = "
this is smaller < than this<br />
this is greater > than this<br />
this is the same = as this<br />
<a href=\"http://www.example.com/example.php?test=test\">This is a link</a><br />
<b>Bold</b> <i>italic</i> etc...";
echo fixtags($string);
?>
Works but this doesn't work:
<?php
$string = "
this is smaller < than this<br />
this is greater > than this<br />
this is the same = as this<br /><a href=\"http://www.example.com/example.php?test=test\">This is a link</a><br />
<b>Bold</b> <i>italic</i> etc...";
echo fixtags($string);
?>
So I add a little workaround at the beginning (before htmlspecialchars):
<?php
$text = preg_replace('/<a/', "\r\n<a", $text);
?>
I don't like that but I don't find other solution... :/