<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'[{&quot;out_trade_no&quot;:&quot;0224085707-3375&quot;,&quot;transaction_id&quot;:&quot;4002362001201702241094854694&quot;,&quot;out_refund_no&quot;:&quot;123&quot;,&quot;total_fee&quot;:&quot;1&quot;,&quot;refund_fee&quot;:&quot;1&quot;}]'</font> <i>(length=239)</i>
post接收到这样的值 使用了html_entity_decode 和htmlspecialchars_decode 只能去掉& 去不掉quot; 整整一天了 怎么解决 在线等
$str = '[{"out_trade_no":"0224085707-3375","transaction_id":"}]';
var_dump($str);
$str = replaceStr($str);
var_dump($str);
function replaceStr($str)
{
// 要替换的选项
$seach = array(""", "&");
// 替换成什么 一一对应
$replace = array("\"", "\&");
return str_replace($seach, $replace, $str);
}
输出结果:
string '[{"out_trade_no":"0224085707-3375","transaction_id":"}]' (length=90)
string '[{"out_trade_no":"0224085707-3375","transaction_id":"}]' (length=55)
客户端进行了2次编码,你需要调用2次html_entity_decode才行
<?php
$s='[{&quot;out_trade_no&quot;:&quot;0224085707-3375&quot;,&quot;transaction_id&quot;:&quot;4002362001201702241094854694&quot;,&quot;out_refund_no&quot;:&quot;123&quot;,&quot;total_fee&quot;:&quot;1&quot;,&quot;refund_fee&quot;:&quot;1&quot;}]';
$s=html_entity_decode(html_entity_decode($s));
?>
<textarea><?php echo $s;?></textarea>