我收到来自端点的api响应:
http://rest.sharethis.com/reach/getUrlInfo.php?url='http://www.mydomain.com/‘
{ "email" : { "inbound" : 47498,
"outbound" : "27459"
},
"facebook" : { "inbound" : 6311,
"outbound" : "2301"
},
"other" : { "inbound" : 2196,
"outbound" : "1456"
},
"sharethis" : { "inbound" : 16536,
"outbound" : "7746"
},
"total" : { "inbound" : 80399,
"outbound" : "40956"
},
"twitter" : { "inbound" : 4946,
"outbound" : "1298"
}
}如何将"total“变量的”inbound+outbound“之和放入一个类似$total的字符串中,以便在php中回显。
发布于 2011-04-07 16:39:33
$decoded = json_decode($string);
$inbound = $decoded->total->inbound;
$outbound = $decoded->total->outbound;
echo "Total: ".($inbound+$outbound);发布于 2011-04-07 16:31:43
这似乎是JSON。您应该查看json_decode(),它将把您的字符串转换为一个可以用标准方式轻松操作的PHP数组。
https://stackoverflow.com/questions/5578135
复制相似问题