现在我知道这样做比较简单,但我想使用表单来获取要在其中使用的URL。我开始使用file_get_contents但后来切换到了fopen。
<?php
$marki = fopen($page, "rb");
$page = $_GET['page'];
echo $marki;
?>
<html>
<body>
<form method="get" action="index.php">
<input type="text" name="page">
<input type="submit" value="grade">
</form>
</body>
</html>
这是我到目前为止使用的代码,我认为答案仍然可以使用file_get_contents,但它不会获取页面内容,因为它一直将获取内容指向存储在我的服务器中的文件,这不是我的意思瞄准。
答案 0 :(得分:2)
在$page
之前设置$marki
,例如 -
$page = $_GET['page'];
$marki = fopen($page, "rb");
答案 1 :(得分:0)
当您使用'file_get_contents'时,您是否在网址前加了“http://”?如果您没有,它将尝试在您自己的服务器上找到该URL。见下文:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
答案 2 :(得分:0)
您也可以尝试cURL。我个人刚刚学会了如何做到这一点,它比file_get_contents
快了大约6倍。
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "url");
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
curl_close($ch);
?>
当你echo $output
时,它会返回它所获得的页面。也可以用它做更多的事情。