如何让我的PHP从XML返回JSON

时间:2015-12-06 12:15:42

标签: php json

我有以下代码,请注意我是使用PHP的新手,我成功地检索了我想要的数据,它是XML格式的,但我想要它在JSON中。我研究了这个,似乎没有任何工作。任何援助将不胜感激。

<?php
ini_set('display_errors', 1);
if( !function_exists("curl_init") && !function_exists("curl_setopt") && 
!function_exists("curl_exec") && !function_exists("curl_close") )
   { 
   echo "Missing Functions";
    } 
else
echo 'curl exists';
$url = 'http://www.somesite.com/blog/feed/';
$client = curl_init();
curl_setopt($client, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json'));
curl_setopt($client, CURLOPT_HTTPHEADER, array( 'Accept: application/json'));
curl_setopt($client, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($client, CURLOPT_URL,$url);
$result = curl_exec($client);
curl_close($client);
echo $result;


?>

0 个答案:

没有答案