admin管理员组文章数量:1421000
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"
".dtd">
<html xmlns="" 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?
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/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/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?
Share Improve this question asked Oct 19, 2011 at 6:47 user893856user893856 1,0293 gold badges15 silver badges21 bronze badges3 Answers
Reset to default 3Just use addslashes
like so:
$a = 'Missing<hr />argument 3 for Class::method(), called in X:\directory\dir2\dir3\x';
$a = addslashes($a);
$a = str_replace(array("\"", "'"), array(""", '''), $a);
As the documentation says:
Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash () and NUL (the NULL byte).
the "\x" at the end of you string is now trying to expect a hexadecimal digit you need to escape the slash in front of the x.
try adding three slashes
$a = 'Missing<hr />argument 3 for Class::method(), called in X:\directory\dir2\dir3\\\x';
I got the solution for this. I was displaying image using physical path in browser: "D:/wamp/www/project/images/imag.png"
-> malformed Unicode character escape sequence
I set it to URL then it resolved my problem "http://siteurl/images/imag.png"
本文标签: javascriptmalformed unicodehexadecimal in phpStack Overflow
版权声明:本文标题:javascript - malformed unicodehexadecimal in php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745337432a2654105.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论