更新:我更改了代碼:如何將json的輸出寫入CSV?
第一個關鍵字正在工作,第二個不寫入csv。多維數組被跳過並寫爲「Array」。沒關係。更新的代碼現在看起來像這樣:
$josn_decoded = json_decode($output, true);
$file_name = "searched_book.csv";
$fp = fopen($file_name, 'w');
foreach($josn_decoded['results'] as $search_result){
fputcsv($fp, $search_result);
}
fclose($fp);
如何在CSV中以行記錄更多關鍵字?
更新2:
這裏是輸出(抱歉,我不能讓它顯示在另一種方式):
Notice: Array to string conversion in /volume2/web/static/buzzsumo/index.php on line 78
array(25) {
["published_date"]=> int(1424081166)
["linkedin_shares"]=> int(43)
["google_plus_shares"]=> int(0)
["meta_keywords"]=> string(27) "payments technology company"
["total_shares_with_pinterest"]=> int(48)
["article_types"]=> array(1) {
[0]=> string(15) "general_article" }
["twitter_shares"]=> int(5)
["og_url"]=> string(131) "http://www.thepaypers.com//online-payments/pay-on-launches-open-payment-platform-for-white-label-payment-gateway-solutions/758641-3"
["url"]=> string(131) "http://www.thepaypers.com//online-payments/pay-on-launches-open-payment-platform-for-white-label-payment-gateway-solutions/758641-3"
["pinterest_shares"]=> int(0)
["id"]=> string(9) "405519905"
["total_shares"]=> int(48)
["title"]=> string(79) "PAY.ON launches Open Payment Platform for white label payment gateway solutions"
["thumbnail"]=> string(51) "http://www.thepaypers.com/images/linkedin-share.png"
["subdomain"]=> string(18) "www.thepaypers.com"
["num_words"]=> int(206)
["domain_name"]=> string(14) "thepaypers.com"
["total_facebook_shares"]=> int(0)
["giveaway"]=> int(0)
["infographic"]=> int(0)
["general_article"]=> int(1)
["guest_post"]=> int(0)
["interview"]=> int(0)
["video"]=> int(0)
["display_title"]=> string(254) "PAY.ON launches Open Payment Platform for white label payment gateway solutions"
}
的article_types實際上可以刪除,因爲在底部有相同再次。此外,我需要第一列中的關鍵字($ search_result)。
謝謝。
[轉換JSON爲CSV格式使用PHP]的可能的複製(http://stackoverflow.com/questions/20667418/converting-json-to-csv- format-using-php) – Wobbles
@Wobbles - 我試過,但沒有奏效。 –
請記住,如果我問CSV的原因? JSON通常更容易與跨平臺和語言一起工作。 – Wobbles