2013-04-08 118 views
0

我想将XE货币转换器集成到我的网站,但希望在我的网站上输出相同的网页,而不是重定向到XE网站,如何实现这一点?与iframe?请你能提供一个例子吗?非常感谢。cakephp和XE货币转换器?

回答

0

你可以从他们的网页数据的饲料,它看起来像: http://www.xe.com/datafeed/

这样,您可以通过PHP /卷曲等检索货币和与它只是正常的数据。

+0

我仍然在规划一个新手,你有什么例子?这将非常感激。谢谢。 – Nick 2013-04-08 10:15:28

+0

嗯,饲料成本540美元,忘记那部分:-) – Nick 2013-04-08 10:27:31

+0

我只是使用这个:https://github.com/dereuromark/tools/blob/master/Lib/CurrencyLib.php – mark 2013-04-08 10:46:03

2

你其实可以提交查询xe.com和使用curl

<?php 


    $url = "http://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=PHP"; 

    $ch = curl_init(); // Initialize a CURL session. 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return Page contents. 
    curl_setopt($ch, CURLOPT_URL, $url); // Pass URL as parameter. 

    $data = curl_exec($ch); // grab URL and pass it to the variable. 
    curl_close($ch); // close curl resource, and free up system resources. 


    $dom = new DOMDocument(); 
    @$dom->loadHTML($data); 

    $xpath = new DOMXPath($dom); 

    $tableRows = $xpath->query('//table//tr'); 

    $details = array(); 

    foreach ($tableRows as $row) { 
      // fetch all 'tds' inside this 'tr' 
      $td = $xpath->query('td', $row); 

      if ($td->length == 3 ): 

       foreach($td as $key => $val){ 

        if($key==0 Or $key ==2) { 

         $details[] = preg_replace('/[^a-zA-Z0-9, \'\.:]*/i', '',$val->nodeValue); 


        } 

       } 


      endif; 
    } 

    print "<pre>"; 
    print_r($details); 
    print "</pre>"; 

    ?> 

访问解析来自它的数据:http://myphptroubles.blogspot.com/2013/09/convert-currency-using-xecom-via-curl.html