After sending the post request I get an answer:

HTTP/1.1 200 OK Server: nginx/1.3.9 Date: Fri, 14 Oct 2016 06:23:56 GMT Content-Type: text/html; charset=utf-8 Content-Length: 1948 Connection: keep-alive X-Powered-By: PHP/5.3.29-1~dotdeb.0 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding {"data":[{"date":"2016-10-14 09:17:10","s1":"2","s3":"4","s5":"6","s7":"8","s9":"10","s11":"12","s13":"14","s15":"16","s17":"18","s19":"20"} 

How do I remove everything that goes to {"data":[{"date":"2016-10-14 09:17:10","s1":"2","s3":"4","s5":"6","s7":"8","s9":"10","s11":"12","s13":"14","s15":"16","s17":"18","s19":"20"} , i.e. I need to use regular expressions to somehow remove all the headers.

  • one
    apparently replacing from the beginning of the line to the curly bracket with a curly bracket. /^.*?{/ - Mike

2 answers 2

With what help do you make a request? CURL? file_get_contents ? Any web framework. You can always get only the response body without headers.

Judging by the format, you get the usual JSON in reply. You can decode the response through json_decode . As a result, the function will return you the usual associative array.

  • I make a request using cUrl and I tried json_decode but returns void, but if you remove the headers, then the json_decode function forms an array without any problems. How to disable the receipt of headers from the server? After all, headlines are needed in principle, because cookies are sent, etc. - Cinema Trailers

The request is made using CURL. To ensure that there are no headers in the response, you need to add this line:

 curl_setopt($datapost, CURLOPT_HEADER, FALSE); 

Also, the question is solved using regular expressions:

replacing from the beginning of the line to the curly bracket with a curly bracket. /^.*?{/

  • one
    This answer has nothing to do with the question. The question is about regular expressions, and the answer is about curl - Dmitriy Simushev
  • @Dmitriy Simushev, when creating a question, I wanted to solve this issue through regular expressions, but I was told in the comment that if it was through curl, I could have done it differently, which I actually did. Given that there is also a solution with regular expressions, so in this question there are two solutions to the problem. - Cinema Trailers
  • one
    In this question it is clearly stated that it is necessary to process the text using a regular expression. There is nothing about CURL in question. As a result, the answer about CURL is wrong. My minus on the answer is about it. - Dmitriy Simushev
  • @Dmitriy Simushev, you are absolutely right, if you look at the situation straightforwardly, like a robot. But we are not robots. Yes, the question is not about CURL, but about CURL is in the first answer, and in this answer I found the true solution and in addition I added a solution through regular expressions. So Dear Dmitry, for the end user, these answers to the question are much more informative. The site, after all, is precisely for this purpose intended for learning and sharing experience - Cinema Trailers
  • And that is why the answer, which is not related to the question, is useless. - Dmitriy Simushev