使用json_decode()函数解码html标签 [英] Decoding html tags using json_decode() function

查看:353
本文介绍了使用json_decode()函数解码html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在PHP中使用json_decode()来解码JSON字符串。我的部分JSON字符串中包含HTML标签。例如。 (要更好地查看代码,请访问 http://gist.github.com/605906

I am trying to decode a JSON string using json_decode() in PHP. Part of my JSON string has HTML tags in it. Eg. (For better view of the code go to http://gist.github.com/605906)

$json = '{"productid" : "prod:a8f2d4ef-108e-5fbf-fa74-595ddc0c7950","memo" : "<div style=\"color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; background-image: initial; background-repeat: initial; background-attachment: initial; background-color: #ffffff; background-position: initial initial; margin: 8px;\">WS1CI metered clack valve, 1\" for softener  P/N: V1CIDME-03</div>"}';

但我得到NULL值,当我做时

var_dump(json_decode($json));

var_dump(json_decode($json, true));


推荐答案

<?php
$arr = array();
$json = '{"productid" : "prod:a8f2d4ef-108e-5fbf-fa74-595ddc0c7950","memo" : "&lt;div style=\"color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; background-image: initial; background-repeat: initial; background-attachment: initial; background-color: #ffffff; background-position: initial initial; margin: 8px;\"&gt;WS1CI metered clack valve, 1\" for softener  P/N: V1CIDME-03&lt;/div&gt;"}';


var_dump(json_decode($json, true));

?>

您需要转换所有html(例如< && gt; c $ c>)

You need to transform all html (like < and > into &lt; and &gt;)

这篇关于使用json_decode()函数解码html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆