title: rework preg_replace with preg_replace_callback
body: <p>I've seen many answers about this but as this one is a bit specific, I still need some help.  I'm trying to update Blogstudio's <a href="https://github.com/Blogestudio/Fix-Serialization/blob/master/fix-serialization.php" rel="nofollow">Fix Serialization</a> script which contains <code>preg_replace()</code> with <code>\e</code> modifier.</p>
  
  <p>The code in question is this:</p>
  
  <pre><code>$data = preg_replace('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!e', "'s:'.strlen(unescape_mysql('$3')).':\"'.unescape_quotes('$3').'\";'", $data);
  </code></pre>
  
  <p>The confusion for me lies in:</p>
  
  <ol>
  <li>Whether those functions are intending to address escaped quotes due to the <code>/e</code> modifier or not?</li>
  <li>What the result should be when there is not a <code>$3</code>?</li>
  </ol>
  
  <p>I had rewritten it as this but still running into warnings and other problems so the result is not the same as what's intended:</p>
  
  <pre><code>$data = preg_replace_callback(
      '!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!',
      function($d) {
          $length = strlen(unescape_mysql($d[3]));
          $value = unescape_quotes($d[3]);
          $result = 's:' . $length . ':\"' . $value . '\";';
          return 's:' . $length . ':\"' . $value . '\";'
      },
      $data
  );
  </code></pre>