How to get status code from header?

the function stream_get_meta_data returns header as an array like this:

 [timed_out] => 
 [blocked] => 1
 [eof] => 
 [wrapper_data] => Array
         [0] => HTTP/1.1 200 OK

I can get the status with $meta[‘wrapper_data’][0] but how can I fetch the status code from the value which would be HTTP/1.1 200 OK as explode by HTTP/1.1 is bad idea. Is it better to use regexp to get the code? or better to use substr($meta['wrapper_data'][0], 9, 3) ?

and between /(?<!\d)[12345]\d\d(?!\d)/ and /[12345]\d\d/ is better to get status code?

sscanf('HTTP/1.1 200 OK', 'HTTP/1.1 %d', $status);
echo $status; // 200

How do you know it is 1.1 for HTTP/1.1? This is why I said explode by HTTP/1.1 is bad idea.

Try this

RFC 2616

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.