Andrew Bro February 2016

HTML entity in JavaScript (XML and PHP)

Newbie in troubles again))) Need yr help guys!

I have an XML file with the data like this:

<Page>
<Content>&lt;p&gt;Article content&lt;/p&gt;&#13;
&#13;
&lt;h1 style="font-style: italic;"&gt;HEADER&lt;/h1&gt;&#13;
&#13;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&#13;
&#13;
&lt;p&gt;&lt;img alt="" src="/upload/images/1.JPG" style="height:51px; width:144px" /&gt;&lt;/p&gt;&#13;
</Content>
</Page>

now I want to extract this data via PHP & replace html by jQ.

<?php
$file = '111.xml';
$XML = simplexml_load_file($file);
$str =$XML->Content;
$str = htmlspecialchars($str, ENT_QUOTES);
JS('var CONV = "'.$str.'"'); //JS function just puts its parametr between <script... tags
echo $str;
?>

<script type="text/javascript">
   $("#debug").html().text(CONV);
</script>     

so the result is NOTHING... if i do Echo - it works, if i replace CONV value with smth like "bla bla bla" - it works either. But with encoded or decoded HTML it shows none...

UPDATE: i still dont know where's the problem. I use "buffer" file as a temporary soultion:

file_put_contents('../plugins/'.pl_DIR().'/buffer.db', $str, LOCK_EX);
JS('$("#editor").load("../../plugins/"+PATH+"/buffer.db")');

Via AJAX the content loads perfectly but anyway Im sure that's diffenetley not the best idea...

Answers


isnisn February 2016

You should try replace

$str = htmlspecialchars($str, ENT_QUOTES);

with

$str = htmlspecialchars_decode($str, ENT_QUOTES);

see http://php.net/manual/en/function.htmlspecialchars-decode.php

I had similar problem the other day, and that solved it for me.

Post Status

Asked in February 2016
Viewed 1,670 times
Voted 9
Answered 1 times

Search




Leave an answer