Last active
March 19, 2018 08:50
-
-
Save hrdtbs/734d204dcc4a07f41ae08735c824c595 to your computer and use it in GitHub Desktop.
PHP get Param, create JSON, create File safety
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 | |
$data = [ | |
"AAA"=>"XXX", | |
"BBB"=>"YYY", | |
]; | |
function createJSON($data){ | |
return json_encode($data, JSON_UNESCAPED_UNICODE); | |
} | |
$json = createJson($data) | |
var_dump($json) |
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 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) |
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 | |
$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