mdref.json config
[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 ## Throws:
15
16 * http\Exception\InvalidArgumentException
17 * http\Exception\BadMethodCallException
18 * http\Exception\BadMessageException
19
20 ## Example:
21
22 <?php
23 $body = new http\Message\Body;
24 $body->addPart(new http\Message("Content-type: text/plain\n\nHello "));
25 $body->addPart(new http\Message("Content-type: text/plain\n\nWorld!"));
26
27 $msg = new http\Message;
28 $msg->setHeader("Content-Type",
29 "multipart/mixed; boundary=" . $body->getBoundary());
30 $msg->setBody($body);
31 var_dump($msg->isMultipart($bnd), $bnd);
32
33 $parts = $msg->splitMultipartBody();
34 var_dump(count($parts));
35 foreach ($parts->reverse() as $part) {
36 echo $part->getBody();
37 }
38 ?>
39
40 Yields:
41
42 bool(true)
43 string(17) "16658735.3fe37486"
44 int(2)
45 Hello World!