• 05-06-2013, 22:00:55
    #1
    Arkadaşlar
    http://www.google.com/ig/calculator?hl=en&q=1USD=?TRY

    Google ın döviz hesaplama hizmeti.

    $adres = "http://www.google.com/ig/calculator?hl=en&q=1USD=?TRY";
    
    $json = file_get_contents($adres);
    
    $para = json_decode($json,true);
    
    echo $para->rhs;
    Bu yöntem ile veriyi çekmeye çalışıyorum beceremedim nerde hata acaba?

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 22:00:55 -->-> Daha önceki mesaj 21:52:51 --

    sorunu çözdüm arkadaşlar;

    google json kodlarını

    Alıntı
    {lhs: "1 U.S. dollar",rhs: "1.87800128 Turkish liras",error: "",icc: true}
    şeklinde veriyor ama olması gereken;

    Alıntı
    {"lhs": "1 U.S. dollar","rhs": "1.87800128 Turkish liras","error": "","icc": true}
    budur. Bunuda

    $forJSON = str_replace(array('lhs', 'rhs', 'error', 'icc'), array('"lhs"', '"rhs"', '"error"', '"icc"'), $json);
    ile çözüyorsunuz.

    yalnız benim anlamadığım bu json tanımlamaları sabit değil mi? google neyin kafasını yaşıyor?

    http://php.net/manual/en/function.json-decode.php
  • 05-06-2013, 22:05:13
    #2
    şöyle bir örnek var işini görür sanırım

    <?php

    function currency($from_Currency,$to_Currency,$amount) {
    $amount = urlencode($amount);
    $from_Currency = urlencode($from_Currency);
    $to_Currency = urlencode($to_Currency);
    $url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Curr ency";
    $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);
    $rawdata = curl_exec($ch);
    curl_close($ch);
    $data = explode('"', $rawdata);
    $data = explode(' ', $data['3']);
    $var = $data['0'];
    return round($var,3);
    }
    ?>

    <?php
    echo currency("USD","TRY",1);
    ?>
  • 05-06-2013, 22:24:48
    #3
    vermiyo sonucu

    $adres = "http://www.google.com/ig/calculator?hl=en&q=1USD=?TRY";
    $adres2 = "http://www.google.com/ig/calculator?hl=en&q=1EUR=?TRY";
    
    $json = file_get_contents($adres);
    $json2 = file_get_contents($adres2);
    
    $forJSON = str_replace(array('lhs', 'rhs', 'error', 'icc'), array('"lhs"', '"rhs"', '"error"', '"icc"'), $json);
    $forJSON2 = str_replace(array('lhs', 'rhs', 'error', 'icc'), array('"lhs"', '"rhs"', '"error"', '"icc"'), $json2);
    	
    $para = json_decode($forJSON,true);
    $para2 = json_decode($forJSON2,true);
    
    echo "Dolar ". substr($para['rhs'],0,4) ."<br>";
    echo "Euro ". substr($para2['rhs'],0,4);
    son durum bu çalışıyor