0

I'm building a new project in angularJS. Backend is PHP with MySQL. PHP API returns data to angular which I need to show in front view.

But HTML tags are not getting decoded in my website. Thay are shown as such. When I try the same in phpfiddle.org, it works.

User submits data through a wysiwyg editor and it is saved in database table something like this:

<p>dfgdfgdfgfd</p><p><br/></p><p>dg</p><p>d</p><p>g</p><p><span class="rangySelectionBoundary" id="selectionBoundary_1472644203224_7186990890070339"></span>df<span class="rangySelectionBoundary" id="selectionBoundary_1472644203224_09491296280590866"></span></p><p><span class="rangySelectionBoundary" id="selectionBoundary_1472644197601_045958185758413816"></span>g<span class="rangySelectionBoundary" id="selectionBoundary_1472644197601_8700155449427347"></span><br/></p>

Following is the method I used to decode HTML in PHP before it returns the data to front end.

<?php
$valueFromDB= "&lt;p&gt;dfgdfgdfgfd&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;dg&lt;/p&gt;&lt;p&gt;d&lt;/p&gt;&lt;p&gt;g&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;rangySelectionBoundary&quot; id=&quot;selectionBoundary_1472644203224_7186990890070339&quot;&gt;&amp;#65279;&lt;/span&gt;df&lt;span class=&quot;rangySelectionBoundary&quot; id=&quot;selectionBoundary_1472644203224_09491296280590866&quot;&gt;&amp;#65279;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;rangySelectionBoundary&quot; id=&quot;selectionBoundary_1472644197601_045958185758413816&quot;&gt;&amp;#65279;&lt;/span&gt;g&lt;span class=&quot;rangySelectionBoundary&quot; id=&quot;selectionBoundary_1472644197601_8700155449427347&quot;&gt;&amp;#65279;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;";

$decoded =  html_entity_decode(htmlspecialchars_decode($valueFromDB,ENT_QUOTES));

echo $decoded;
?>

It works in fiddle but in real website, this is how it looks.

enter image description here

Why it's not working in website when it works in a fiddle?

2
  • 3
    don't use angular template expression (e.g. {{}}). use ng-bind-html attribute Commented Sep 1, 2016 at 7:27
  • i found answer here: stackoverflow.com/questions/26064309/… Commented Sep 1, 2016 at 7:56

1 Answer 1

3

if you are trying to print the query result using angular's $http, then try using ng-bind-html

<div ng-bind-html="queryResult"></div>

this directive requires angular-sanitize.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.