Ciao a tutti,
utilizzo da un po' di tempo uno script per la conversione della valuta da EUR verso AED (Emirati Arabi).
Lo script in questione, SE VOLETE UTILIZZARLO, è questo, ho eliminato i commenti per renderlo più leggibile in questa pagina:
Codice PHP:
<?php
class GoogleCurrencyConvertor{
private $rate="";
private $reverseRate="";
public function __construct($amount, $currFrom, $currInto){
if (trim($amount)=="" ||!is_numeric($amount)) {
trigger_error("Please enter a valid amount",E_USER_ERROR);
}
$return=array();
$gurl="http://www.google.com/search?&q=$amount+$currFrom+in+$currInto";
$html=$this->getHtmlCodeViaFopen($gurl);
$pattern='/<h2 class=r(.*)\<\/h2\>/Uis';
preg_match_all($pattern,$html,$return,PREG_PATTERN_ORDER);
if (isset($return[0][0])) {
$rate=strip_tags($return[0][0]);
$tmp=explode("=",$rate);
$rate=$tmp[1];
$this->rate=$this->getIntegers($rate);
$this->reverseRate=1/$this->rate;
}
else {
$this->rate=$this->reverseRate="Google could not convert your request. Please try again.";
}
}
private function getIntegers($str){
$ret="";
$str=trim($str);
for ($i=0;$i<strlen($str);$i++){
$code=ord($str[$i]);
if( ($code>47 && $code<58) || $code==46) {
$ret.=$str[$i];
}
}
return $ret;
}
function getHtmlCodeViaFopen($url){
$returnStr="";
$fp=fopen($url, "r") or die("ERROR: Failed to open $url for reading via this script.");
while (!feof($fp)) {
$returnStr.=fgetc($fp);
}
fclose($fp);
echo $returnStr;
return $returnStr;
}
function getRate(){
return $this->rate;
}
function getReverseRate(){
return $this->reverseRate;
}
}
$googleCurrencyConvertor = new GoogleCurrencyConvertor(1,"EUR","AED");
echo $rate = round($googleCurrencyConvertor->getRate(), 2);
?>
Per farvi vedere l'esempio online di quello che succede ho preparato due link:
il primo funziona a dovere, ritorna (per debug) la pagina parsata dallo script ed al fondo il risultato della conversione. si trova a questo indirizzo
Il secondo riporta una pagina di errore, che non so interpretare a questo punto, e si trova qui
Mi dareste una mano a capire? Si tratta di un problema dell'hosting?
Grazie