Writing a PHP Array to a File generates Binary instead of Plain-Text
<p>I'm trying to write an array or object to a file in plain-text (Not Binary), however whenever I loop over the array and look at the file I'm receiving Binary instead.</p>

<p><code>$this-&gt;user</code> and <code>$this-&gt;temp_files['in_file_name']</code> are passed into the function prior.</p>

<pre><code>$user_array = (array)$this-&gt;user;
$data = "";

foreach ($user_array as $key =&gt; $value) {
    $data .= "$key $value\n";
}

file_put_contents($this-&gt;temp_files['in_file_name'], $data);
</code></pre>

<p>If i just pass a string into <code>$data</code> it gets written to the file as plain-text, but when I loop over the object or array I receive binary. Is there a way to get the plain-text version of this array in the file?</p>

<p><code>$this-&gt;user</code> is a database row as an object from <code>Ion_Auth</code> called by:</p>

<pre><code>$this-&gt;user =$this-&gt;ion_auth-&gt;user($this-&gt;user_id)-&gt;row();
</code></pre>

<p>Here is a portion of the output of the file </p>

<blockquote>
  <p>4461 7465 2054 7565 7364 6179 204f 6374 6f62 6572 2033 302c 2032 3031 3269 6420 320a 6970 5f61 6464 7265 7373 207f 0000 010a 7573 6572 6e61 6d65 2062 7261 6e64 6f6e 2062 6f73 7765 6c6c 0a70 6173 7377 6f72 6420 6539 3936 3630 6665 3039 3535 6663 3862 3431 6639 3838 3066 3639 6131 6664 6635 </p>
</blockquote>

<p>The var_dump of the user array is: (I've changed some values for data security reasons)</p>

<pre><code>array (size=22)
  'id' =&gt; string '2' (length=1)
  'ip_address' =&gt; string '��' (length=4)
  'username' =&gt; string 'brandon' (length=15)
  'password' =&gt; string 'changed' (length=40)
  'salt' =&gt; null
  'email' =&gt; string 'brandon@changed.net' (length=27)
  'activation_code' =&gt; null
  'forgotten_password_code' =&gt; null
  'forgotten_password_time' =&gt; null
  'remember_code' =&gt; string 'changed' (length=40)
  'created_on' =&gt; string '1337702147' (length=10)
  'last_login' =&gt; string '1351607850' (length=10)
  'active' =&gt; string '1' (length=1)
  'first_name' =&gt; string 'Brandon' (length=7)
  'last_name' =&gt; string 'changed' (length=7)
  'company' =&gt; string 'changed' (length=17)
  'phone' =&gt; string '804-814-changed' (length=12)
  'store' =&gt; string 'mechanicsville' (length=14)
  'delivery' =&gt; string '1' (length=1)
  'receiveEmails' =&gt; string '1' (length=1)
  'customerType' =&gt; string 'business' (length=8)
  'user_id' =&gt; string '2' (length=1)
</code></pre>

<p>If I do a <code>file_get_contents</code> on the file it can be echoed back in correctly, but I wish the file were stored as plain-text.</p>
