php:json

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
php:json [2022/05/31 22:35] – 作成 babaphp:json [2022/05/31 22:42] (現在) – [Reference] baba
行 1: 行 1:
 ====== php でjsonのread and write ====== ====== php でjsonのread and write ======
 phpでのjsonファイル読み込みと書き出しの超速レシピ用メモ 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/attic/php/json.1654004135.txt.gz
  • 最終更新: 2022/05/31 22:35
  • by baba