Hi guys.

This is nice little code to convert currency on websites using google currency convert service, but it needs some modification, so can any one please help with it, it returns this when testing it:

Notice: Undefined offset: 1 in D:\wamp\www\index.php on line 9
Notice: Undefined offset: 3 in D:\wamp\www\index.php on line 9
Notice: Undefined offset: 1 in D:\wamp\www\index.php on line 13
Notice: Undefined offset: 3 in D:\wamp\www\index.php on line 14

After searching online I found that the array for the variable $expl must be defined, so I tried to define it but it seems that I am still not getting it right, here is the code:

<?php

function currency_convert($amount, $from, $to) {
$result = @file_get_contents('http://www.google.com/ig/calculator?hl=en&q='.$amount.$from.'=?'.$to);
$expl = explode('"', $result);

//$expl[0] = "{lhs:";
//$expl[1] = "100 U.S. dollars";
//$expl[2] = ",rhs:";
//$expl[3] = "$to";

if ($expl[1] == ' ' || $expl[3] == ' ') {
return false;
} else {
return array (
$expl[1],
$expl[3]
);
}
}

$amount = 1;
$from = ('usd');;
$to = ('gbp');

$conversion = currency_convert($amount, $from, $to); {
echo number_format((float)$conversion[1], 2);
}

?>

Can any one please teach me how to define it correctly?