Note that there are some explanatory texts on larger screens.

plurals
  1. POSplit cURL header info into array
    primarykey
    data
    text
    <p>Consider the following PHP cURL command:</p> <pre><code>$url = 'http://bit.ly/faV1vd'; $_h = curl_init(); curl_setopt($_h, CURLOPT_HEADER, 1); curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1); curl_setopt($_h, CURLOPT_HTTPGET, 1); curl_setopt($_h, CURLOPT_URL, $url); curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false ); curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 ); $return = curl_exec($_h); </code></pre> <p>This returns:</p> <pre><code>HTTP/1.1 301 Moved Server: nginx Date: Sun, 29 Apr 2012 12:48:07 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Set-Cookie: _bit=4f9d3887-00215-020af-2f1cf10a;domain=.bit.ly;expires=Fri Oct 26 12:48:07 2012;path=/; HttpOnly Cache-control: private; max-age=90 Location: http://www.macroaxis.com/invest/market/VZ--Sat-Feb-26-06-16-35-CST-2011?utm_source=twitterfeed&amp;utm_medium=twitter MIME-Version: 1.0 Content-Length: 209 </code></pre> <p>I want to split the header info into an array, as follows</p> <pre><code>[Status] =&gt; HTTP/1.1 301 Moved, [Server] =&gt; nginx, [Date] =&gt; Sun, 29 Apr 2012 12:48:07 GMT, ... [Content-Length] =&gt; 209 </code></pre> <p>So: - the first line (HTTP/1.1 301 Moved) should be the value of [Status] - all other header info should be split on <code>:</code></p> <p>I'm not succeeding in splitting the header info:</p> <pre><code>explode("\r\n\r\n", $return); explode("\r\n", $return); </code></pre> <p>This doesn't split the header into an array (to further split on <code>:</code>, etc. as expected. What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload