I want to return HTML from PHP. I found a solution from StackOverflow which is insert JSON_HEX_QUOT | JSON_HEX_TAG
after array in json_encode
but it does not work for me. If I simply echo it right away it's working and displays the text on page but it doesn't work with json_encode
.
Here is my code:
<?php
header('Content-Type: application/json');
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mcblog";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "select ID,post_parent,post_title,post_content,post_date from wp_posts where post_content<>'' and post_title<>'' order by post_date desc limit 0,10";
$result = $conn->query($sql);
$data=array();
$row = $result->fetch_assoc();
$html=strip_tags($row["post_content"]);
$snippetData=array('status'=>'1','data'=>$row["post_content"]);
echo json_encode($snippetData, JSON_HEX_QUOT | JSON_HEX_TAG);
?>