title: PHP Language Editor, Array Keys
body: <p>I have found the script.
  <a href="http://www.aota.net/forums/showthread.php?t=24155" rel="nofollow">http://www.aota.net/forums/showthread.php?t=24155</a></p>
  
  <p>My lang.php</p>
  
  <pre><code>&lt;?php
  $Lang = array(
  'TEXT'      =&gt; "baer",
  'GRET'      =&gt; "hallo",
  'FACE'      =&gt; "face",
  'HAPY'      =&gt; "happy",
  'TOOL'      =&gt; "tool",
  );
  </code></pre>
  
  <p>My edit.php</p>
  
  <pre><code>&lt;?
  // edit the values of an array ($Lang["key"] = "value";) in the file below
  $array_file = "lang.php";
  
  // if POSTed, save file
  if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
      unset($_POST['submit']);  // remove the submit button from the name/value pairs
      $new_array = "";          // initialize the new array string (file contents)
      $is_post = true;          // set flag for use below
  
      // add each form key/value pair to the file
      foreach (array_keys($_POST) as $key)
          { $new_array .= "\$Lang[\'$key\'] =&gt; \"".trim($_POST[$key])."\",\n"; }
  
      // write over the original file, and write a backup copy with the date/time
      write_file($array_file, $new_array);
      write_file($array_file . date("_Y-m-d_h-ia"), $new_array);
      }
  
  // write a file
  function write_file($filename, $contents)
      {
      if (! ($file = fopen($filename, 'w'))) { die("could not open $filename for writing"); }
      if (! (fwrite($file, $contents))) { die("could not write to $filename"); }
      fclose($file);
      }
  
  // read the array into $Lang[]
  $file_lines = file($array_file);
  $Lang = array();
  foreach ($file_lines as $line)
      {
      list($b4_key, $key, $b4_value, $value) = explode('"', $line);
      if (preg_match("/Lang/", $b4_key))
          { $Lang[$key] = $value; }
      }
  ?&gt;    
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Language Editor&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;&lt;?= $array_file ?&gt;&lt;/h1&gt;
  &lt;? if (!isset($is_post)) { ?&gt;
  &lt;form action="&lt;?= $_SERVER['PHP_SELF'] ?&gt;" method="POST"&gt;
  &lt;? } ?&gt;
  &lt;table&gt;
  &lt;?
  // loop through the $Lang array and display the Lang value (if POSTed) or a form element
  foreach ($Lang as $key =&gt; $value)
      {
      echo "&lt;tr&gt;&lt;td&gt;$key&lt;/td&gt;&lt;td&gt;";
      echo isset($is_post) ? "= \"$value\"": "&lt;input type=\"text\" name=\"$key\" value=\"$value\"&gt;";
      echo "&lt;/td&gt;&lt;/tr&gt;\n";
      }
      ?&gt;
  &lt;/table&gt;
  &lt;? if (!isset($is_post)) { ?&gt;
  &lt;p&gt;&lt;input type="submit" name="submit" value="Save"&gt;&lt;/p&gt;
  &lt;/form&gt;
  &lt;? } ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Unfortunately I can not read array and Keys from lang.php.</p>
  
  <p>Script writer, writes:
  all lines in array.txt did do set $ Bid [] will be lost.</p>
  
  <p>But I want lang.php after the change save as a PHP file that would go?</p>
  
  <p>I want to create a drop-down list and load array with matching keys, change key text and save.</p>
  
  <p>I thank you in advance for your help!</p>