Q:

preg_slit not working like it should? - php

preg_slit function is not working correctly for me. Function outputs 1 value in the array instead of 3. Demo
$response = '--batch_QXn9PvafngA_AAdxhnxliYc
Content-Type: application/http
Content-ID: response-3368-post

HTTP/1.1 200 OK
ETag: "3057934386064000"
Content-Type: application/json; charset=UTF-8
Date: Thu, 14 Jun 2018 09:06:33 GMT
Expires: Thu, 14 Jun 2018 09:06:33 GMT
Cache-Control: private, max-age=0
Content-Length: 860

--batch_QXn9PvafngA_AAdxhnxliYc
Content-Type: application/http
Content-ID: response-3369-post

HTTP/1.1 200 OK
ETag: "3057934386064000"
Content-Type: application/json; charset=UTF-8
Date: Thu, 14 Jun 2018 09:06:33 GMT
Expires: Thu, 14 Jun 2018 09:06:33 GMT
Cache-Control: private, max-age=0
Content-Length: 860

}

--batch_QXn9PvafngA_AAdxhnxliYc--';

echo '<pre>';
print_r( preg_split("/(\--batch_*:)+/", $response) );

I am doing something wrong?

A:

I don't know what kind of results you are looking for exactly, but there are some problems here:

* is a quantifier so _*: means 0 or more _ characters followed by a :. You don't have this in your text anywhere, so it will never match anything.
If you want to match over multiple lines to get to a :, you need the s modifier.

So your modified expression would look something like this, using non-greedy matching for the characters before the ::
/(--batch_.*?:)+/s

This you would probably need to adapt further to get what you want.

