title: Convert C++ code to PHP?
body: <p>I am trying to write a struct in php, i know there is no such thing in php, but at least get it working somehow...</p>
  
  <p>C++:</p>
  
  <pre><code> // The struct
      typedef struct data
      {
          char numbers[20];
          char numbers2[50];
          char number3[6];
          char sometext[100];
      }data_t;
  
      data_t config;
  
      char numbers[20] = "12345.12345";
      char numbers3[6] = "12345";
      char sometext[100] = "asdsadsad";
  
      // Storing into struct
      strcpy_s(config.numbers, numbers);
      strcpy_s(config.numbers3, numbers3);
      strcpy_s(config.sometext, sometext);
  
      // Serializing struct to test.dat
      ofstream output_file("test.dat", ios::binary);
      output_file.write((char*)&amp;config, sizeof(config));
      output_file.close();
  
      // Reading from it
      ifstream input_file("test.dat", ios::binary);
      input_file.read((char*)&amp;master, sizeof(master));
  
      cout &lt;&lt; "NUMBERS : " &lt;&lt; master.numbers &lt;&lt; endl;
      cout &lt;&lt; "NUMBERS3 : " &lt;&lt; master.numbers3 &lt;&lt; endl;
      cout &lt;&lt; "SOMETEXT : " &lt;&lt; master.sometext &lt;&lt; endl;
      cout &lt;&lt; endl &lt;&lt; endl;
  </code></pre>
  
  <p>Now storing with c++ in the struct, then reading it works just fine, but i want to store in that file trough php, then read it from c++, so i have:</p>
  
  <p>PHP:</p>
  
  <pre><code>$data = Array();
  $data['numbers'] = "12345.12345";
  $data['numbers3'] = "12345";
  $data['sometext'] = "abcdfghs";
  
  $fp=fopen("test.dat","wb") or die("Stop! i kill you...");
  foreach($data as $key =&gt; $value){
  echo 'written:'.$value;
  fwrite($fp,$value."\t");
  }
  </code></pre>
  
  <p>Now what is happening is:</p>
  
  <pre><code>NUMBERS : 12345.12345  12345   abcdfghs
  NUMBERS3 :
  SOMETEXT :
  </code></pre>
  
  <p>So as you can see, it`s not good, also i noticed a difference when writing to file from c++ (contains binary data), while writing to file from php is just plain text.</p>
  
  <p>Some help would be apreciated, many thanks!</p>