Jump to content

Curl return values


EchoFool

Recommended Posts

Hey,

 

I just managed to get my curl script working and when i execute it with :

 

echo curl_exec ($ch).'<br>'; 

 

I get this as a result, which i am trying to understand how i manipulate it to assign to variables..:

s=507183574&d=0&n=name.part5.rar1

 

Firstly that last character 1 i don't know why it keeps returning a 1 even when its incorrect it still does it which seems to be some thing im doing wrong... but it returns this string - how do i put them into variables :S ? It looks like GETs from how its worded :S

Link to comment
https://forums.phpfreaks.com/topic/197948-curl-return-values/
Share on other sites

Since it is a query string, parse_str should suit you well.

 

As for it returning one because you do not have the returntransfer set in the curl_setopt. So it is displaying the contents to the browser, there is no need to echo in this case. To fix it add this before you run the exec:

 

curl_setopt($ch, CURL_RETURNTRANSFER, true); // allows for transfer to be put into a string

 

Then change your echo to:

$return = curl_exec($ch);

 

Then add the parse string logic:

parse_str($return, $valueArray);
echo "<pre>", print_r($valueArray), "</pre>";

 

Should do you right.

Link to comment
https://forums.phpfreaks.com/topic/197948-curl-return-values/#findComment-1038708
Share on other sites

It is an associative array, meaning it is not number indexed. You have to call it by 'd':

If($valueArray['d'] == 0){ echo 'hi'; }

 

If you want it to be both you can do this, however, the associative should be enough:

$i=0;
foreach ($valueArray as $val) {
    $valueArray[$i++] = $val;
}

 

Will give you a numbered index as well as the associative. So yea either or I guess.

Link to comment
https://forums.phpfreaks.com/topic/197948-curl-return-values/#findComment-1038731
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.