File "index.php"
Full path: /www/OperationManagement/nasu/index.php
File size: 1.35 KiB (1384 bytes)
MIME-type: text/html
Charset: utf-8
<HTML>
<HEAD>
<META Http-Equiv="Content-Type" Content="text/html;charset=UTF-8">
<TITLE>JSON変換出力</TITLE>
<LINK REL="stylesheet" HREF="mstmnt.css" TYPE="text/css">
</HEAD>
<BODY>
<?php
$file_name[0] = "/www/OperationManagement/nasu/json/01.json";
$file_name[1] = "/www/OperationManagement/nasu/json/03.json";
$file_name[2] = "/www/OperationManagement/nasu/json/04.json";
json($file_name[0]);
print "OK";
/**
* JSONファイル読込み処理
* @param file 読込み対象ファイル
* return HTML
*/
function json($file){
// jsonファイルを指定(直接指定する場合)
// $file = "holiday.json";
// JSONファイルを動的に切替えるため引数で指定
// ファイルの内容を全て文字列に読み込む
$json = file_get_contents($file);
// 文字エンコーディングの変換(文字化け対策)
$json = mb_convert_encoding($json, "UTF-8", "ASCII, JIS, UTF-8, EUC-JP, SJIS-WIN");
// JSONデータを連想配列に変換
$arr = json_decode($json, true);
$html = "<div class='json_list'>";
// 空判定
if (!empty($arr)) {
$html .= "<p>";
foreach ($arr as $key => $value) {
$html .= $key . " : " . $value . "<br />";
}
$html .= "</p>";
} else {
$html .= "<p>Nothing...</p>";
}
$html .= "</div>";
echo $html;
}
?>