title: How do I decode a MIME-encoded, multiparted string in PHP?
body: <p>I'm getting some data from a server and among other things I receive what looks like a MIME-encoded file (or files), as if it was an email body</p>
  <p>This is an example of a two files response:</p>
  <pre><code>MIME-Version: 1.0
  Content-Type: multipart/mixed; boundary=________________314159265358979323846
  
  --________________314159265358979323846
  Content-Type: application/xml; name=&quot;1140800950110001200045971048.xml&quot;
  Content-Transfer-Encoding: base64
  Content-Disposition: attachment; filename=&quot;1140800950110001200045971048.xml&quot;
  
  PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZG [trimmed]
  aW5pY2FsRG9jdW1lbnQ+Cg==
  
  --________________314159265358979323846
  Content-Type: application/pdf; name=&quot;1140800950110001200045971048.pdf&quot;
  Content-Transfer-Encoding: base64
  Content-Disposition: attachment; filename=&quot;1140800950110001200045971048.pdf&quot;
  
  JVBERi0xLjQKJaqrrK0KNCAwIG9i [trimmed]
  mCjIzMzA3CiUlRU9GCg==
  
  --________________314159265358979323846--
  </code></pre>
  <p>I've got to extract the two files (in fact just the pdf would be fine) and then base64_decode them for displaying</p>
  <p>There are a couple functions/libraries that would do this easily but it seems they all want an IMAP stream rather than a string, is a regex my only choice?</p>