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:

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

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

$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">

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);

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


isnisn February 2016

You should try replace

$str = htmlspecialchars($str, ENT_QUOTES);


$str = htmlspecialchars_decode($str, ENT_QUOTES);


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


Leave an answer