title: PHP write to file
body: <p>below is some code I am using to "translate" a map array into SQL code so I can easily update my database when I have updated my game map. As you can see it prints out the SQL code onto the screen so I can copy and paste it.</p>
  
  <p>As my maps will get bigger this will become inefficient as it will crash the browser due to mass output, so instead I am wondering if it is possible to make it create a .txt file and write all of the data to it instead of printing onto the screen?</p>
  
  <pre><code>&lt;?php
  if (isset($_POST['code'])){
  $map = $_POST['code'];
  $map = preg_replace("/,\\s*}/i", "}", $map);
  $map = str_replace("{", "[", $map);
  $map = str_replace("}", "]", $map);
  $map = json_decode('[' . $map . ']');
  
  $arrayCount1 = 0;
  $arrayCount2 = -1;
  
  $H = sprintf('%05d', 00000);
  $V = sprintf('%05d', 00000);
  $id = 1;
  
  echo "INSERT INTO `map` (`id`, `horizontal`, `verticle`, `image`) VALUES" . "&lt;br /&gt;";
  
  for ($count1 = 0; $count1 &lt; sizeof($map[0]); $count1++){
  $arrayCount2++;
  $arrayCount1 = 0;
  $V = sprintf('%05d', $V + 1);
  $H = sprintf('%05d', 00000);
  
  for ($count2 = 0; $count2 &lt; sizeof($map); $count2++){
  echo "(" . $id . ", '" . $H . "', '" . $V . "', '" . $map[$arrayCount1][$arrayCount2] . "')," . "&lt;br /&gt;";
  $arrayCount1++;
  $id++;
  $H = sprintf('%05d', $H + 1);
  }
  }
  }
  ?&gt;
  </code></pre>