User Tools

Site Tools


programming:php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
programming:php [2021/04/14 02:57]
nanodano
programming:php [2022/03/13 19:00] (current)
nanodano ↷ Links adapted because of a move operation
Line 17: Line 17:
 </code> </code>
  
-See the [[:web_servers|web servers]] page for more info on configuring +See the [[:web|web servers]] page for more info on configuring 
  
 ===== Built-in webserver ===== ===== Built-in webserver =====
Line 213: Line 213:
 $image->cropImage(200,200, 50,0); $image->cropImage(200,200, 50,0);
 $image->writeImage($outFile); $image->writeImage($outFile);
 +</code>
 +
 +
 +==== JSON ====
 +
 +<code php json.php>
 +<?php
 +# PHP object -> JSON string
 +$json_string = json_encode(['my_key' => 'my value', 'other_key' => 'other value']);
 +echo $json_string;
 +
 +# JSON string -> PHP object
 +$json_string = '{"my_key":"my value","other_key":"other value"}';
 +$my_array =  json_decode($json_string);
 +print_r($my_array)
 +
 +// Dump/read from file
 +file_put_contents('test.json', json_encode([2, 4, 6]));
 +$my_array = json_decode(file_get_contents('test.json'));
 +print_r($my_array);
 </code> </code>
  
Line 402: Line 422:
 */ */
 </code> </code>
 +
 +
  
programming/php.1618369040.txt.gz · Last modified: 2021/04/14 02:57 by nanodano