PHP Classes

File: testPson.php

Recommend this page to a friend!
  Classes of zinsou A.A.E.Moïse   PHP WWJSON   testPson.php   Download  
File: testPson.php
Role: Example script
Content type: text/plain
Description: example script
Class: PHP WWJSON
Convert JSON data into other formats
Author: By
Last change: change example script as PHP CLASSES avoid upload a key file
Date: 7 years ago
Size: 2,860 bytes
 

Contents

Class file image Download
<?php
require_once('Pson.class.php');
echo
'<h1>Play with JSON and PHP array</h1>';
echo
'<h2>how to use</h2>';
$x=new Pson();
echo(
$x);
var_dump($x());

$x='{
    ":database":{
        ":crud-action":"create",
        "name":"another_unify_schools",

        ":table-group":[
            {
                ":crud-action":"create",
                "name":"students",
                "columns":[
                    {
                        "name":"id",
                        "data-type":"int",
                        "primary-key":true
                    },
                    {
                        "name":"first_name",
                        "data-type":"varchar(20)",
                        "default":"\'samuel\'"
                    },
                    {
                        "name":"last_name",
                        "data-type":"varchar(20)"
                    },
                    {
                        "name":"class",
                        "data-type":"varchar(10)"
                    }
                ]
            },
            {
                ":crud-action":"create",
                "name":"faculty",
                "columns":[
                    {
                        "name":"fac_id",
                        "data-type":"int",
                        "auto_increment":true,
                        "primary-key":true
                    },
                    {
                        "name":"first_name",
                        "data-type":"varchar(20)"
                    },
                    {
                        "name":"last_name",
                        "data-type":"varchar(20)"
                    }
                ]
            },
            {
                ":crud-action":"create",
                "name":"subjects",
                "columns":[
                    {
                        "name":"subject_id",
                        "data-type":"int",
                        "auto_increment":true,
                        "primary-key":true
                    },
                    {
                        "name":"subject_name",
                        "data-type":"varchar(30)"
                    },
                    {
                        "name":"subject_faculty",
                        "data-type":"int",
                        "foreign-key":"(subject_faculty)",
                        "references":"faculty(fac_id)",
                        "on-update":"cascade",
                        "on-delete":"set null"
                    }
                ]
            }
        ]
    }
}'
;

echo
'<pre>';
echo
'<h2>json to really simple array</h2>';
print_r( Pson::json_toarray($x));
echo
'<h2>json to simple flatten array </h2>';
print_r( $r=Pson::json_toFlatten($x));
echo
'<h2>Flatten array to multidimensionnal array encoded in json</h2>';
print_r( Pson::Flatten_toMulti_json($r));
echo
'<h2>Encrypted PHP variable built from json</h2>';
print_r($e=Pson:: phpArray_son($x,false,true));
$i=explode('::',$e["key"]);
echo
'<h2>Decrypt encrypted PHP variable built from json</h2>';
print_r(Pson::unserialize_Pason($e["encrypted"],$i));
echo
'<h2>Encrypt Json</h2>';
print_r($t=Pson::json_crypt($x));
echo
'<h2>Decrypt encrypted Json</h2>';
print(
Pson::cjson_decrypt($t));
echo
'<h2> Unserialize serialized PHP Array built from Json</h2>';
print_r(Pson::unserialize_Pason(Pson::phpArray_son($x,false,false)));
echo
'<h2>convert to PHP Array, serialize,Encrypt and save to a file from Json</h2>';
Pson::phpArray_son($x,'test',true);
echo
'<h2>Unserialize serialized and encrypted PHP Array built from Json</h2>';
print_r(Pson::unserialize_Pason('test.pason','test.pason.key'));
echo
'<h2>serialized and encrypted PHP Array to Json</h2>';
print_r(Pson::Pason_toJson('test.pason','test.pason.key'));
echo
'</pre>';



?>