php - 从外部网站获取内容

标签 php jquery file-get-contents

假设我想从德国交易所提取当前的比特币汇率(欧元)bitcoin.de每次我访问我的网站时都会获取该值(因此没有缓存)。我能够提取 PHP 中的值:

// fetch contents from bitcoin.de
$url = 'https://www.bitcoin.de/de/';
$content = file_get_contents($url);

// cut everything before specified text
$content = strstr($content, "Aktueller Bitcoin Kurs");

// extract rate
$rate = strstr($content, "<b>");
$rate = substr($rate, 3);
$rate = strstr($rate, "€", true);

echo $rate . " EUR"; // e.g. 105,51 EUR

这工作正常并打印正确的当前值,因为它可以在 bitcoin.de 网站上找到。但我正在获取整个网站内容,减去我不需要的所有内容,然后返回它。

我的问题:有没有办法(也许也使用 jQuery)更有效地解决这个问题;因此不获取整个网站代码而只获取费率值?

最佳答案

有许多 API 可用于访问该数据。虽然有更复杂的 API,但您要查找的信息可在以下位置找到:

http://data.mtgox.com/api/2/BTCUSD/money/ticker

关于php - 从外部网站获取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16252410/

相关文章:

Php - While 循环数据 MySQL

JQuery 查找性能

javascript - dc.js - 使用 jquery 数据表插件的数据表

PHP file_put_contents 从 php 文件保存

php - 为什么无法将网页保存到我的/var/www目录中?

php - 如何避免 "Entities passed to the choice field must be managed. Maybe persist them in the entity manager?"

php 日期函数返回一个我没想到的结果

php - file_get_contents() 的最大 URI 长度

javascript - 同一页面上的两个 JQuery Ajax 调用

powershell - 在 Powershell 中,处理超过 1GB 的文件时收到 "OutOfMemoryException"