I want to give a text to a DIV. This text has HTML tags, so I thought its enough to escape the ” and ‘ characters. Full code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
</head>
<body>
<div id="lay">.</div>
<?php
$a = 'Missing<hr />argument 3 for Class::method(), called in X:\directory\dir2\dir3\x';
$a = str_replace(array("\"", "'"), array(""", '''), $a);
?>
<script type="text/javascript">
document.getElementById('lay').innerHTML = '<?php echo $a; ?>';
</script>
</body>
</html>
but firefox said its malformed. Even htmlspecialchars() aint work. How the heck to escape this string? And why it fails?
Just use
addslasheslike so:As the documentation says: