title: PHP Unserialize data for use in array - sub standard characters in string
body: <p>I am using a jQuery plugin of nestable forms and storing the order of these in a database using serialize (achieved through JS). Once I retrieve this data from the database I need to be able to unserialize it so that each piece of data can be used.</p>
  
  <p>An example of the data serialized and stored is</p>
  
  <pre><code>[{"id":"H592736029375"},{"id":"K235098273598"},{"id":"B039571208517"}]
  </code></pre>
  
  <p>The number of ID's stored in each serialized data varies and the JS plugin adds the [ and ] brackets around the serialization.</p>
  
  <p>I have used <a href="http://www.unserialize.com/" rel="nofollow">http://www.unserialize.com/</a> to test an unserialization of the data and it proves successful using print_r. I have tried replicating this with the following code:</p>
  
  <pre><code>&lt;?php
  print_r(unserialize('[{"id":"H592736029375"},{"id":"K235098273598"},{"id":"B039571208517"}]'));
  ?&gt;
  </code></pre>
  
  <p>but I get an error. I am guessing that I need to use something similar to strip_tags to remove the brackets, but am unsure. The error given is as follows</p>
  
  <pre><code>Notice: unserialize(): Error at offset 0 of 70 bytes
  </code></pre>
  
  <p>Once I have the unserialized data I need to be able to use each ID  as a variable and I am assuming to do so I need to do something as:</p>
  
  <pre><code>&lt;?php
  $array = unserialize('[{"id":"H592736029375"},{"id":"K235098273598"},{"id":"B039571208517"}]');
  
  foreach($array as $key =&gt; $val)
  {
      // Do something here, use each individial ID however
      // e.g database insert using $val['id']; to get H592736029375 then K235098273598 and finally B039571208517
  }
  ?&gt;
  </code></pre>
  
  <p>Is anyone able to offer any help as to how to strip the serialized data correctly to have the ID's ready in an array to then be used in the foreach function?</p>
  
  <p>Much appreciated.</p>