0

I am using cURL to fetch data from another site into my application. I am getting the data in exactly the same format as it is displayed on the browser.

What I need is to get the data in a form of an array.

I even tried using file_get_contents, but it also doesn't gives me the data in array (as it outputs in array).

4
  • show us how your data Looks like and show us your CURL code... Commented Nov 5, 2012 at 5:05
  • We're good, but we're not psychic. We can't read your mind to see how this data looks. Commented Nov 5, 2012 at 5:08
  • This is my code:$url='bpwr.XXX.com:8026?DataDate=2012-11-05';curl_setopt($ch,CURL…); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); print_r($data); curl_close($ch); Commented Nov 5, 2012 at 6:15
  • This gives me the whole screen, whereas my requirement to get just the content of the page in the form of the array Commented Nov 5, 2012 at 6:16

2 Answers 2

0

to take the cookie data and the location of a header, I use this code, hope this help.

You can try with any other information that the header can give you.

...
$result = curl_exec($ch);
curl_close($ch);

$var = explode("\n", $result);
$header = array();

foreach( $var as $row ) {
    if( strpos( strtolower($row), "set-cookie: " ) !== false ) {
        $header['set-cookie'] = str_ireplace("Set-Cookie: ", "", $row);
    } else if( strpos( strtolower($row), "location: " ) !== false ) {
        $header['location'] = str_ireplace("Location: ", "", $row);
    }
}

PS: I was mistaken, i believed that it was about the Header not the HTML content.

Sign up to request clarification or add additional context in comments.

Comments

0

You should use the xpath. check it on the PHP & xPath Question or try search with xpath.

3 Comments

This is my code:$url='bpwr.XXX.com:8026?DataDate=2012-11-05';curl_setopt($ch,CURL…; curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); print_r($data); curl_close($ch);
This gives me the whole screen, whereas my requirement to get just the content of the page in the form of the array.
Have you ever used xpath? It will load you whole html and you can fetch whatever element you have required from that html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.