functions.phpに記載
<?php
function get_json($path){
$json = file_get_contents($path); //変数にjsonファイルの内容をすべて文字列に読み込む
$json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN'); //文字化けしないように
$arr = json_decode($json,true); //受け取ったデータを連想配列にする(trueがないとなりません)
return $arr;
}
?>$json_arr = get_json("http://hoge.jp/common/test.json");データ取得例
<?php
$names = $json_arr["type_name"];
foreach($names as $name){
$texts = $json_arr["test"][$name]["texts"];
$type = $json_arr["test"][$name]["type"]
echo '<h2>'.$type.'</h2>'
foreach($texts as $text){
echo '<p>'.$text.'</p>';
}
}
?>