這將是本站有史以來最基本的問題!我是新來的編程和很新的遊離鹼 - 但我無法找到我需要的任何地方,所以這裏去答案...PHP解析Freebase查詢
我使用從here PHP基本查詢在我的PHP文件:
<?php
// include('.freebase-api-key');
$service_url = 'https://www.googleapis.com/freebase/v1/topic';
$topic_id = '/en/bob_dylan';
$params = array('key'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$url = $service_url . $topic_id . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$topic = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $topic['property']['/type/object/name']['values'][0]['value'];
?>
我有這個工作,以便它在我的網站上顯示結果(本例中只是名字'鮑勃迪倫')。我的問題是,我需要拉下幾條信息,比如出生日期,國籍,死亡等等......但我無法弄清楚如何通過echo $ topic [?]來訪問,解析和顯示它。 ?????] ;.
如何弄清楚在這裏放什麼:echo $ topic ['????'];
我想在我的網站上是這樣的結果:
Name: Bob Dylan
Born: May 24, 1941
Died: -
Nationality: American
Parents: ???, ???
Children: ???, ???
道歉極其福利局問題,只是不知道還有什麼地方轉彎。
謝謝!
。 。 。 。 。 感謝尼古拉斯的迴應。我跟着那個網站,你發佈並試用了此相反:
$service_url = 'https://www.googleapis.com/freebase/v1/topic';
$topic_id = '/en/bob_dylan';
$params = array('key'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$url = $service_url . $topic_id . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$topic = json_decode(curl_exec($ch), true);
curl_close($ch);
parse_str($topic, $txArr);
var_dump($txArr);
但是,讓我在我的網站下面的結果:陣列(1){[「陣列」] =>字符串(0)「」}
我聽到許多手掌打在額頭上的聲音,因爲他們讀到這個...就像我說我是一個新手,並感謝一些幫助,所以謝謝!
看看這個:HTTP://計算器。 com/questions/2459865/how-do-i-parse-the-response-i-get-back-from-curl – nicolas 2013-05-02 22:11:49