php no good escape

一世执手 提交于 2019-12-12 02:14:44

问题


I have a script like this:

document.getElementById('debugLayer').innerHTML = '<?php foreach (self::$errorLogs as $item) { echo htmlentities ($item, ENT_QUOTES).'<hr />'; } ?>';

where $errorLogs is an array of list. But it must have not escape correctly, since firefox say to this:

Error: malformed Unicode character escape sequence
Source File: X
Line: 553, Column: 63
Source Code:
document.getElementById('debugLayerDIVcontent_10').innerHTML = '&lt;span style=&quot;background-color:yellow;&quot;&gt;&lt;i&gt;Missing argument 3 for Upload::getDamagesStatisticsByUserID(), called in action_index.php on line 149 and defined&lt;/i&gt;&lt;/span&gt;, in &lt;span style=&quot;background-color:#40FF40;&quot;&gt;&lt;b&gt;Upload.php&lt;/b&gt;&lt;/span&gt; at &lt;i&gt;&lt;span style=&quot;background-color:red; color:white;&quot;&gt;256&lt;/span&gt;&lt;/i&gt; [&lt;b&gt;2&lt;/b&gt;]<hr />&lt;span style=&quot;background-color:yellow;&quot;&gt;&lt;i&gt;Undefined variable: join&lt;/i&gt;&lt;/span&gt;, in &lt;span style=&quot;background-color:#40FF40;&quot;&gt;&lt;b&gt;Upload.php&lt;/b&gt;&lt;/span&gt; at &lt;i&gt;&lt;span style=&quot;background-color:red; color:white;&quot;&gt;266&lt;/span&gt;&lt;/i&gt; [&lt;b&gt;8&lt;/b&gt;]<hr />';

what can be wrong?


回答1:


htmlentities() accepts a 3rd argument to define the used charset. The default is Latin1, set it to UTF-8 when you're using UTF-8



来源:https://stackoverflow.com/questions/7800454/php-no-good-escape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!