Skip to content

Instantly share code, notes, and snippets.

@hrdtbs
Last active March 19, 2018 08:50
Show Gist options
  • Save hrdtbs/734d204dcc4a07f41ae08735c824c595 to your computer and use it in GitHub Desktop.
Save hrdtbs/734d204dcc4a07f41ae08735c824c595 to your computer and use it in GitHub Desktop.
PHP get Param, create JSON, create File safety
<?php
$data = [
"AAA"=>"XXX",
"BBB"=>"YYY",
];
function createJSON($data){
return json_encode($data, JSON_UNESCAPED_UNICODE);
}
$json = createJson($data)
var_dump($json)
<?php
function getParams(){
$return = array();
if (isset($_GET) && is_array($_GET)) {
$return += $_GET;
}
if (isset($_POST) && is_array($_POST)) {
$return += $_POST;
}
return $return;
}
$params = getParams();
var_dump($params)
<?php
$path = "../data/test.json";
function safeCreatefile($path, $json){
file_put_contents($path, $json, LOCK_EX);
}
safeCreateFile($path, $json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment