Skip to content

Instantly share code, notes, and snippets.

@KentaYamada
Created May 11, 2017 09:39
Show Gist options
  • Save KentaYamada/13c39a0202322fb636548a460c400228 to your computer and use it in GitHub Desktop.
Save KentaYamada/13c39a0202322fb636548a460c400228 to your computer and use it in GitHub Desktop.
JSONファイルを読み込んで配列にして返す
<?php
function from_json($filename) {
if(!file_exists($filename)) {
throw new Exception($filename.' not found.');
}
$json_text = file_get_contents($filename);
if(!$json_text) {
throw new Exception('Failed read '.$filename);
}
$json = mb_convert_encoding($json_text, 'UTF8', 'ASCII, JIS, UTF-8, EUC-JP,SJIS-WIN');
return json_decode($json, true);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment