0

I am getting a error in the one line of code here:

$converted = preg_replace("/[^0-9.]/", "", $converted[1]);

Does anybody know what's causing it?

public function convertCurrency($amount, $from, $to) {
$url = "https://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$rawdata = curl_exec($ch);
if ($rawdata === FALSE) {
echo "cURL Error: " . curl_error($ch);
} else {
preg_match("/<span class=bld>(.*)<\/span>/", $rawdata, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return number_format(round($converted, 3), 2);
}
curl_close($ch);
}
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 1
    Looks like PHP code. It may help for getting responses to add the php tag then ( [php] ). – Louis Langholtz Sep 14 '17 at 20:11
  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – ChrisGPT was on strike Sep 14 '17 at 21:19
  • yes its php as in the title it says AdminController.php theres over 1500 lines of code but stops here at line 1410 it has an open php and a close php tag – Ed Meredith Sep 15 '17 at 02:12

1 Answers1

0

The code was correct. Google now has a hidden input in the form. The input is dynamic and changes each time. This was giving the error. Thank you for looking at the problem.