【发布时间】:2017-09-26 02:36:02
【问题描述】:
我想用file_get_contents() 阅读我网站上的其他网站。我的价值可以与 javascript 合并。
我的网站页面是:http://example.com/page.html#2010/09/awesome.html
JAVASCRIPT
var hash = window.location.hash.substr(1);
// results: 2010/09/awesome.html
PHP
$hash = "<script>document.write(hash);</script>";
$resultLink = "http://www.external-site.com/" .$hash;
$content = file_get_contents($resultLink);
$first_step = explode("<div class='post-entry'>" , $content );
$second_step = explode("</div>" , $first_step[1] );
echo $second_step[0];
这里 $resultLink 是:http://www.external-site.com/2010/09/awesome.html
但是file_get_contents($resultLink)无法打开页面。
如何修复此代码?
【问题讨论】:
-
您收到什么错误?
-
@Enstage 无法使用
file_get_contents打开外部站点上的内容 -
我怀疑您正在尝试在 PHP 中执行 JS / 在 JS 中执行 PHP,这不是它的工作方式。 JS在客户端(在用户的浏览器中)执行,PHP是服务器端。
标签: javascript php