$_POST parser - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of $_POST parser.php
- <?php
- #Example Array
- $_POST = array(
- "valor1" => 1200,
- "valor2" => "texto",
- "valor3" => true,
- "valor4" => '{"seclvl_text":"datp","seclvl_boolean":"false"}',
- );
- function ValidateJson($Var) {
- if (!is_array($Var)) {
- return ((json_decode($Var) != null) AND (is_object(json_decode($Var)) OR is_array(json_decode($Var)))) ? true : false;
- } else {
- return false;
- }
- }
- function buildVirtualData($data) {
- if (is_array($data)) {
- $result = [];
- foreach ($data as $key1 => $val1) {
- $valJson = ValidateJson($val1);
- if ($valJson) {
- $jsonObj = json_decode($val1, true);
- $result[$key1] = buildVirtualData($jsonObj);
- } elseif ($valJson == false && is_array($val1)) {
- foreach ($val1 as $key2 => $val2) {
- $result[$key1][$key2] = buildVirtualData($val2);
- }
- } else {
- if ($val1 === 'true') {
- $val1 = true;
- } else if ($val1 === 'false') {
- $val1 = false;
- }
- $result[$key1] = $val1;
- }
- }
- return $result;
- } else {
- if (ValidateJson($data)) {
- $jsonObj = json_decode($data, true);
- return buildVirtualData($jsonObj);
- } else {
- return $data;
- }
- }
- }
- $data = buildVirtualData($_POST);
- echo '<pre>';
- echo var_dump($data);
- echo '</pre>';