Created
May 11, 2017 09:39
-
-
Save KentaYamada/13c39a0202322fb636548a460c400228 to your computer and use it in GitHub Desktop.
JSONファイルを読み込んで配列にして返す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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