user893856
user893856

Reputation: 1029

php no good escape

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?

Upvotes: 0

Views: 380

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117354

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

Upvotes: 1

Related Questions