0

XE Currency コンバーターを自分の Web サイトに統合したいのですが、自分の Web サイトの同じページに出力を表示し、XE Web サイトにリダイレクトされないようにしたいのですが、これを実現するにはどうすればよいですか? 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 に答える