EchoFool Posted April 8, 2010 Share Posted April 8, 2010 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 Quote Link to comment Share on other sites More sharing options...
premiso Posted April 8, 2010 Share Posted April 8, 2010 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. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted April 8, 2010 Author Share Posted April 8, 2010 I tried that and that returned : s=996147200&d=0&n=name.part5.rar Array ( [1] => ) 1 Quote Link to comment Share on other sites More sharing options...
premiso Posted April 8, 2010 Share Posted April 8, 2010 Post the code you tried it with. EDIT: An amendment to my first post: curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // allows for transfer to be put into a string Try that and it should work. Sorry about that. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted April 8, 2010 Author Share Posted April 8, 2010 Thanks thats perfect although do u happen to know why i get this number "1" appearing after it : Array ( [id0] => 0 [s] => 996147200 [d] => 0 [n] => name.part5.rar ) 1 < < < Quote Link to comment Share on other sites More sharing options...
premiso Posted April 8, 2010 Share Posted April 8, 2010 It was how I used print_r. Change it to this to remove the 1. parse_str($return, $valueArray); echo "<pre>", print_r($valueArray, true), "</pre>"; As the true will make it not return a true/false value. print_r for more information. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted April 8, 2010 Author Share Posted April 8, 2010 Ok thanks! Final question sorry I tried this after it : If($valueArray[4] == 0){ echo 'hi'; } Seems to be unhappy with it - (in this case [4] is : [d] => 0 ) Am i getting it correct on how i grab the values? Quote Link to comment Share on other sites More sharing options...
premiso Posted April 8, 2010 Share Posted April 8, 2010 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. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted April 8, 2010 Author Share Posted April 8, 2010 Thanks dude! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.