javascript - malformed unicodehexadecimal in php - Stack Overflow

I want to give a text to a DIV. This text has HTML tags, so I thought its enough to escape the " a

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("&quot;", '&#039;'), $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("&quot;", '&#039;'), $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 badges
Add a ment  | 

3 Answers 3

Reset to default 3

Just 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("&quot;", '&#039;'), $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"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745337432a4623170.html

相关推荐

  • javascript - malformed unicodehexadecimal in php - Stack Overflow

    I want to give a text to a DIV. This text has HTML tags, so I thought its enough to escape the " a

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信