Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7858541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:30:03+00:00 2026-06-02T21:30:03+00:00

Consider the following PHP cURL command: $url = ‘http://bit.ly/faV1vd’; $_h = curl_init(); curl_setopt($_h, CURLOPT_HEADER,

  • 0

Consider the following PHP cURL command:

$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);

This returns:

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&utm_medium=twitter
MIME-Version: 1.0
Content-Length: 209

I want to split the header info into an array, as follows

[Status] => HTTP/1.1 301 Moved,
[Server] => nginx,
[Date] => Sun, 29 Apr 2012 12:48:07 GMT,
...
[Content-Length] => 209

So:
– the first line (HTTP/1.1 301 Moved) should be the value of [Status]
– all other header info should be split on :

I’m not succeeding in splitting the header info:

explode("\r\n\r\n", $return);
explode("\r\n", $return);

This doesn’t split the header into an array (to further split on :, etc. as expected. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:30:04+00:00Added an answer on June 2, 2026 at 9:30 pm

    Use this to split your header into an array

    $myarray = array();
    $data = explode("\n",$return);
    
    $myarray['status'] = $data[0];
    
    array_shift($data);
    
    foreach($data as $part){
         $middle = explode(":",$part);
         $myarray[trim($middle[0])] = trim($middle[1]);
    }
    
    print_r($myarray);
    

    As well as use curl_setopt($_h, CURLOPT_NOBODY, 1);
    if you need to return only header.

    More info can be found here

    http://altafphp.blogspot.com/2012/04/get-http-headers-of-any-site-using-curl.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following URLs: http://www.mydomain.com/a/test.php https://www.mydomain.org/a/b/test.php http://www.mydomain.co.nr/a/b/c/test.php https://www.mydomain.com/a/b/c/d/test.php http://www.mydomain.co.uk/a/b/c/d/e/test.php https://www.mydomain.co.au.nm/a/b/c/d/e/f/test.php?var1=test1&var2=test2 Now I want
Consider the following command line output using grep: [gjempty@gjempty]$ find . -name *.php |
Consider the following scenario: http://www.restserver.com/example.php returns some content that I want to work with
Consider the following HTML: <div id=myfavorites> <p><button id=saveFav>Save my favorites</button> </p> <p><a href=http://bit.ly/fzgxya>http://bit.ly/fzgxya</a> <a
Consider the following: wrap callback in anonymous function (works) $('#updateView').change(function(e) { $.post(URL + actions/updateView.php,
Consider the following php code used for HTML output: echo <div id='logo2'> <a href='if(checkLanguage())
Consider the following code: <?php $conn = mysql_connect('localhost', 'username', 'password'); mysql_select_db('database', $conn); ?> This
Consider the following: <?php //daytime_check.php $is_daytime = false; if ($is_daytime) { echo '1'; }
consider the following code scenario: <?php //widgetfactory.class.php // define a class class WidgetFactory {
Consider the following directory structure: ROOT ------ images ............... logo.png ------ includes ............... vars.php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.