0

我想在我的网站中集成 XE 货币转换器,但希望在我的网站相同页面上输出而不被重定向到 XE 网站,如何实现?与 iframe?请问你能给我举个例子吗?非常感谢。

4

2 回答 2

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

于 2013-09-17T09:14:27.917 回答
0

您可以从他们的页面订购数据提要,如下所示: http ://www.xe.com/datafeed/

有了它,您可以通过 PHP/curl 等检索货币并像普通数据一样使用它。

于 2013-04-08T10:02:23.807 回答