-1

Similar to Problem with cURL I have an api response which is returned at numerals only

If I break the code with a print_r($rate); which is where I point the curl response to an ajax error shows the correct response is being sent back as "ResponseText:0.09876787(command: . . . etc - but apparently it is not being put into the variable by

   $rate = curl_exec($ch);

my code runs fine at /devel/php and is returned into the variable and the code which uses $rate also runs to completion without any json decode and it is being sent as a html page if anything - as the number alone shows in a browser and page inspection shows html headers. The number 0.09876787 is what should be $rate.

I have fixed the http calls so no & is being changed to &amp as I have seen happen and the post above refers to also

So it runs correctly in the php devel window but not in the actual module

Is there something else different drupal 7 does to the response or needs to be done in code?

0

The website called to by curl needed to return a simple string integer - but it returns a single line html page which displays the string integer sought in the browser window with the sought after response integer in it. Thus what worked was to call website to get the response as a single mixed string and then strip everything but numbers and the decimal point with this code below

 $dom = str_get_html(curl_exec($ch));  // get html as dom    
 $str = $dom->save();  //  save as string
 $rate = preg_replace("/[^.0-9]/", "", $str);  // strip text

Which works and absolutely produces a string integer variable - and after all that I discovered the real issue was elsewhere in the module code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.