Posted By

ghprod on 12/19/11


Tagged


Versions (?)

Better Than get_headers With cURL


 / Published in: PHP
 

Better Than get_headers With cURL

  1. function curl_header($url)
  2. {
  3. $ch = curl_init();
  4.  
  5. curl_setopt($ch, CURLOPT_URL, $url);
  6. curl_setopt($ch, CURLOPT_HEADER, TRUE);
  7. curl_setopt($ch, CURLOPT_NOBODY, TRUE);
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  9. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  10.  
  11. $out = explode("\n", curl_exec($ch));
  12.  
  13. curl_close($ch);
  14.  
  15. foreach ($out as $header) {
  16. preg_match('#(.*?)\:\s(.*)#', $header, $matches);
  17. $head[$matches[1]] = $matches[2];
  18. }
  19.  
  20. return $head;
  21. }

Report this snippet  

You need to login to post a comment.