donglunzai4288 2016-08-22 18:30
浏览 298
已采纳

即使我尝试编码JSON_HEX_QUOT |,Json_Encode也不返回html JSON_HEX_TAG

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);
?>
  • 写回答

1条回答

  • douxiong4892 2016-08-23 17:36
    关注

    I wanted to achieve HTML without tags and return that result in JSON format. So I done it with this:

    echo json_encode(array("id"=>"1","data" => utf8_encode(strip_tags($row["post_content"]))));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形