PHP文件获取内容-Don';我不知道如何选择一个特定的类/分区
我试图在我的网站上显示€(数字),但我不知道如何单独显示,并将其变成变量,而不是显示整个内容。我现在有这个密码PHP文件获取内容-Don';我不知道如何选择一个特定的类/分区,php,Php,我试图在我的网站上显示€(数字),但我不知道如何单独显示,并将其变成变量,而不是显示整个内容。我现在有这个密码 <?php $content = file_get_contents("https://www.stratisrate.com/"); echo $content; ?> 但是我不知道如何只显示数字(我已经看了几个教程,但我仍然无法理解它。您可以按照注释中的建议解析DOM,也可以使用JSON响应通过AJAX刷新内容 试试
<?php
$content = file_get_contents("https://www.stratisrate.com/");
echo $content;
?>
但是我不知道如何只显示数字(我已经看了几个教程,但我仍然无法理解它。您可以按照注释中的建议解析DOM,也可以使用JSON响应通过AJAX刷新内容 试试这个:
$result = json_decode(file_get_contents('https://www.stratisrate.com/json/load/rate.json'), true);
// this will print the whole array under the key 'euro'
print_r($result['euro']);
//This will get you just the value you asked for
print_r($result['euro']['rate']);
JSON响应如下所示:
{
"euro": {
"rate_title": "euro",
"rate": "3.37428419",
"strat": 0.296359,
"symbol": "€"
},
"dollar": {
"rate_title": "dollar",
"rate": "3.33987",
"strat": 0.299413,
"symbol": "$"
},
"bitcoin": {
"rate_title": "bitcoin",
"rate": "0.00163",
"strat": 613.496933,
"symbol": "Ƀ"
}
}
我通过查看google chrome开发工具中网络选项卡下的XHR请求发现了这一点。
然后,我只需检查打开该XHR调用的url并获得结果(不需要身份验证令牌或登录)您可以按照注释中的建议解析DOM,或者使用JSON响应通过AJAX刷新内容 试试这个:
$result = json_decode(file_get_contents('https://www.stratisrate.com/json/load/rate.json'), true);
// this will print the whole array under the key 'euro'
print_r($result['euro']);
//This will get you just the value you asked for
print_r($result['euro']['rate']);
JSON响应如下所示:
{
"euro": {
"rate_title": "euro",
"rate": "3.37428419",
"strat": 0.296359,
"symbol": "€"
},
"dollar": {
"rate_title": "dollar",
"rate": "3.33987",
"strat": 0.299413,
"symbol": "$"
},
"bitcoin": {
"rate_title": "bitcoin",
"rate": "0.00163",
"strat": 613.496933,
"symbol": "Ƀ"
}
}
我通过查看google chrome开发工具中网络选项卡下的XHR请求发现了这一点。
然后,我只需检查打开该XHR调用的url并获得结果(无需身份验证令牌或登录)阅读关于DomDocument和解析HTMLH的文章可能会对您有所帮助。@splash58已经尝试过了,但仍然无法理解您的代码,我们将尝试在中查找错误it@splash58这不是一个错误,我只是不知道怎么做。在这里你可以看到我的意思:页面中有很多东西,但我想显示的唯一数字是欧元和itRead about DomDocument and parsing htmlth后面的数字这篇文章可能会帮助您。@splash58已经尝试过了,但仍然无法与我们相比您的代码,我们将尝试在中查找错误it@splash58这不是一个错误,我只是不知道怎么做。在这里,你可以看到我的意思:这页有很多东西,但唯一的数字我想展示的是欧元及其背后的数字这与我尝试过的有所不同,但效果非常好,感谢ICE solution+1,用于您的搜索:)@FluffyMe-如果HTML包含您需要的数据,您应该这样做,而不是毫无疑问地删除HTML。我回来将其作为答案发布。松鼠!嗯,这与我尝试过的不同,但它非常有效,感谢CE solution+1,用于您的搜索:)@FluffyMe-如果HTML包含您需要的数据,您应该这样做,而不是毫无疑问地删除HTML。我回来是想将其作为答案发布。松鼠!