Created
March 7, 2016 20:14
-
-
Save zoerab/3eb4bd433747215d57eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function var2console($var, $name='', $now=false) | |
| { | |
| if ($var === null) $type = 'NULL'; | |
| else if (is_bool ($var)) $type = 'BOOL'; | |
| else if (is_string ($var)) $type = 'STRING['.strlen($var).']'; | |
| else if (is_int ($var)) $type = 'INT'; | |
| else if (is_float ($var)) $type = 'FLOAT'; | |
| else if (is_array ($var)) $type = 'ARRAY['.count($var).']'; | |
| else if (is_object ($var)) $type = 'OBJECT'; | |
| else if (is_resource($var)) $type = 'RESOURCE'; | |
| else $type = '???'; | |
| if (strlen($name)) { | |
| str2console("$type $name = ".var_export($var, true).';', $now); | |
| } else { | |
| str2console("$type = " .var_export($var, true).';', $now); | |
| } | |
| } | |
| function str2console($str, $now=false) | |
| { | |
| if ($now) { | |
| echo "<script type='text/javascript'>\n"; | |
| echo "//<![CDATA[\n"; | |
| echo "console.log(", json_encode($str), ");\n"; | |
| echo "//]]>\n"; | |
| echo "</script>"; | |
| } else { | |
| register_shutdown_function('str2console', $str, true); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment