文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== php でjsonのread and write ====== phpでのjsonファイル読み込みと書き出しの超速レシピ用メモ ===== Write ===== <file> $obj = '{ "name": "馬場哲晃", "gender": "男"}'; $data = json_decode($obj,true); $json = fopen('sample.json', 'w+b'); fwrite($json, json_encode($data)); fclose($json); </file> ===== Read ===== <file> $json_string = file_get_contents("sample.json"); //文字列データとしてjsonファイルを読み込み。 $json_string_encoded = mb_convert_encoding($json_string, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN'); $json_decoded = json_decode($json_string_encoded,true); </file> ===== Reference ===== * https://uxmilk.jp/14767 * https://hara-chan.com/it/programming/php-json-data-read-write/ /home/users/2/lolipop.jp-4404d470cd64c603/web/ws/data/pages/php/json.txt 最終更新: 2022/05/31 22:42by baba