title: PHP: serializing and unserializing string containing escaped characters
body: <p>How do I correctly serialize and unserialize a string containing escaped characters?</p>
  
  <p>Given:</p>
  
  <pre><code>$data = "\'test\'";
  $out= serialize($data);
  print_r($out); // -&gt;  s:8:"\'test\'";
  </code></pre>
  
  <p>The problem here is, that the string length is not accepted by unserialize:</p>
  
  <pre><code>$out = 's:8:"\'test\'"';
  var_dump(unserialize($out)); // -&gt; bool(false)
  </code></pre>
  
  <p>But if I change the string length to 6 (ignoring the escape chars):</p>
  
  <pre><code>$out = 's:6:"\'test\'"';
  var_dump(unserialize($out)); // -&gt; string(6) "'test'"
  </code></pre>
  
  <p>It unserializes correctly.</p>
  
  <p>What would be a good way of handling this problem?</p>