-2

I am trying to pass html (image tag) inside an array_push:

array_push($result, array("id"=>$value, "label"=>'<img src="images/image.jpg" alt="">'.$value, "value"=>strip_tags($key)));

The problem is that the html is rendered in the page like this:

&lt;img src="images/image.jpg" alt=""&gt;

so I get just text:

<img src="images/image.jpg" alt=""> 

instead of an image.

I process the array $result with json_encode:

echo json_encode($result);
Yannis
  • 912
  • 2
  • 14
  • 34

2 Answers2

0

You are probably using something like htmlentities() or addslashes() in your render function. Without, it should work.

Alp
  • 29,274
  • 27
  • 120
  • 198
-1

Apparently, array_push() is converting HTML entities similar to the htmlentities() function. I've never looked into that behavior before, but a simple solution would be when you pop the HTML data from you array, process it with html_entity_decode() before output.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133