45 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
function populateWithPost ()
 | 
						|
{
 | 
						|
    $str_data = file_get_contents("data.json");
 | 
						|
	$config = json_decode($str_data,true);
 | 
						|
 | 
						|
  foreach ($_POST as $key => $value) {
 | 
						|
      echo "$key => $value";
 | 
						|
	  $config[$key] = trim($value); //here you can add a filter, like htmlentities ...
 | 
						|
	  echo $config;
 | 
						|
  }
 | 
						|
 | 
						|
  return $config;
 | 
						|
  
 | 
						|
}
 | 
						|
?>
 | 
						|
 | 
						|
<?php
 | 
						|
if($_POST)
 | 
						|
{
 | 
						|
	$config = populateWithPost();
 | 
						|
	$fh = fopen("data_out.json", 'w')
 | 
						|
      or die("Error opening output file");
 | 
						|
	fwrite($fh, json_encode($data,JSON_UNESCAPED_UNICODE));
 | 
						|
	fclose($fh);
 | 
						|
}
 | 
						|
// Read the file contents into a string variable,
 | 
						|
// and parse the string into a data structure
 | 
						|
$str_data = file_get_contents("data.json");
 | 
						|
$config = json_decode($str_data,true);
 | 
						|
 
 | 
						|
// Modify the value, and write the structure to a file "data_out.json"
 | 
						|
//
 | 
						|
$data["YourName"] = "Swimmi2ng";
 | 
						|
?>
 | 
						|
 | 
						|
<form action="read.php" method="post">
 | 
						|
 <?php
 | 
						|
 foreach ($config as $key => $value) {
 | 
						|
    echo "<label for='$key'>$key</label>"; 
 | 
						|
	echo "<input name='$key' type='text' value='$value' /><p />";
 | 
						|
}
 | 
						|
?>
 | 
						|
 <input type="submit" value="Save" />
 | 
						|
</form>
 |