Last active
May 17, 2016 06:57
-
-
Save dkstar88/5c584c27036b1ff266bfef209c8e0818 to your computer and use it in GitHub Desktop.
json2php is script convert Json object to PHP array. Combine it with "pbpaste | php ~/scripts/json2php.php | pbcopy", from terminal, makes quick tool for convert json to php.
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
<?php | |
function var_export54($var, $indent="") { | |
switch (gettype($var)) { | |
case "string": | |
return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"'; | |
case "array": | |
$indexed = array_keys($var) === range(0, count($var) - 1); | |
$r = []; | |
foreach ($var as $key => $value) { | |
$r[] = "$indent " | |
. ($indexed ? "" : var_export54($key) . " => ") | |
. var_export54($value, "$indent "); | |
} | |
return "[\n" . implode(",\n", $r) . "\n" . $indent . "]"; | |
case "boolean": | |
return $var ? "TRUE" : "FALSE"; | |
default: | |
return var_export($var, TRUE); | |
} | |
} | |
$content = ''; | |
while (false !== ($line = fgets(STDIN))) { | |
// echo $line; | |
$content .= $line; | |
} | |
//$content = file_get_contents('php://input'); | |
$data = json_decode($content, true); | |
echo var_export54($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment