From the database I receive the following text:
<div onclick="alert('código inyectado');">Texto</div>
[img]http://www.hobbyconsolas.com/sites/hobbyconsolas.com/public/media/image/2015/07/503196-halo-5-guardians-nuevos-datos-campana-cooperativa.jpg[/img]
Y aquà una URL: [url]https://www.google.es/?gws_rd=ssl[/url]
Bueno pues vamos [b]a ver si esto funciona[/b] porque "todavÃa" no lo sé [i][u]bien[/u][/i]
This text is stored in a variable $texto
. After going through htmlspecialchars () to avoid code injection, I try to replace the html characters by their counterparts:
$texto = str_replace(""","\"",$texto); //para comillas
$texto = str_replace("<","<",$texto); // para <
$texto = str_replace(">",">",$texto); // para >
But none is modified. I have been doing tests and it seems that it is because of the character &
, if I delete it it is modified.