function.phpを編集して取得したjsonデータをテーブルで出力したい
wordpressで簡単なwebサイトを作成しています。twitterAPIでトレンドのjsonデータを取得し、なるべくきれいに表示させようとしていますがfunction.phpを編集してもなかなかできません。jsonデータをjson
、配列に直したものをarr
としています。
該当のソースコード
php
1 ini_set('display_errors', true); 2 error_reporting(E_ALL); 3 function h($string) 4 { 5 return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); 6 } 7 8echo "<html lang='ja' dir='ltr'>"; 9echo "<head>" 10 echo "<meta charset='utf-8'>" 11 echo "<title>test</title>" 12echo "</head>" 13echo "<body>" 14echo "<table border="1" width="1000" >" 15 16 foreach ($arr[0]['trends'] as $item) : 17 echo "<tr>" 18 echo "<td width="300">"<?= h($item['name']) echo "</td>" 19 20 echo "</tr>" 21 endforeach ; 22 23 echo $arr[0]['created_at']; 24 echo $arr[0]['locations'][0]['woeid']; 25 echo $arr[0]['locations'][0]['name']; 26 27echo "</table>" 28echo "</body>" 29echo "</html>" 30
私的にここを直せばできると考えていますが、どうすべきか全くわかりません。
補足情報
使用しているjsonデータの例を記述します。
json
1[ 2 {"trends": 3 [ 4 {"name":"\u5EA6","url":"http://search?","promoted_content":null,"query":"%E5%BA%A6","volume":10583 5 }, 6 {"name":"aaa","url":"http://bbb","promoted_content":null,"query":"ccc","volume":12345 7 }, 8... 9 {"name":"AAA","url":"http://BBB","promoted_content":null,"query":"CCC","volume":67890 10 } 11 ], 12 "as_of":"2018-07-06T08:17:55Z","created_at":"2018-07-06T08:09:27Z","locations": 13 [ 14 {"name":"Kitakyushu","woeid":1110809 15 } 16 ] 17 } 18]
回答1件
あなたの回答
tips
プレビュー