message
[mdref/mdref-http] / http / Message / splitMultipartBody.md
1 # http\Message http\Message::splitMultipartBody()
2
3 Splits the body of a multipart message.
4 See http\Message::isMultipart() and http\Message\Body::addPart().
5
6 ## Params:
7
8 None.
9
10 ## Returns:
11
12 * http\Message, a message chain of all messages of the multipart body.
13
14 ## Example:
15
16 <?php
17 $body = new http\Message\Body;
18 $body->addPart(new http\Message("Content-type: text/plain\n\nHello "));
19 $body->addPart(new http\Message("Content-type: text/plain\n\nWorld!"));
20
21 $msg = new http\Message;
22 $msg->setHeader("Content-Type",
23 "multipart/mixed; boundary=" . $body->getBoundary());
24 $msg->setBody($body);
25 var_dump($msg->isMultipart($bnd), $bnd);
26
27 $parts = $msg->splitMultipartBody();
28 var_dump(count($parts));
29 foreach ($parts->reverse() as $part) {
30 echo $part->getBody();
31 }
32 ?>
33
34 Yields:
35
36 bool(true)
37 string(17) "16658735.3fe37486"
38 int(2)
39 Hello World!