Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- --- info ---
- jDump usa json_encode per stampare nella console js una variabile da php
- tipo $_SERVER, non funziona con $GLOBALS
- --- install ---
- - includere jdump.php all inzio dello script
- - per il dump di una variabile/array usare jd(var/array,'label')
- - per stampare l'aoutput usare jsOut() da inserire in qualsiasi punto del file, tipo nel footer
- */
- class jDump{
- public $script;
- public $input;
- public $alljd;
- public function __construct($input='') {
- $this->input = array();
- }
- public function o() {
- //var_dump($this->input);
- $js = "<script class='jDumper'>";
- $js .= "jDumpStr='".json_encode($this->input,JSON_HEX_TAG | JSON_UNESCAPED_SLASHES |JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)."';\n";
- $js .= "jDump = JSON.parse(jDumpStr);\n";
- $js .="console.log('jDump:',jDump);\n";
- $js .= "</script>";
- echo $js;
- }
- public function in($in,$label=false) {
- //var_dump($this->input);
- if($label){
- $this->input[$label] = $in;
- }
- else
- {
- $this->input[] = $in;
- }
- }
- }
- $jd = new jDump();
- function jd($in,$label=false){
- global $jd;
- $jd->in($in,$label);
- }
- function jdOut(){
- global $jd;
- $jd->o();
- }
- ?>
Add Comment
Please, Sign In to add comment