我正在尝试访问然后打印(或只是能够使用)使用 PHP 的任何网站的源代码。我不是很有经验,现在我想我可能需要使用 JS 来完成这个。到目前为止,下面的代码访问网页的源代码并显示网页......我想要它做的是显示源代码。本质上,也是最重要的,我希望能够将源代码存储在某种变量中,以便以后使用。并最终逐行阅读 - 但这可以稍后解决。
$url = 'http://www.google.com';
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo get_data($url); //print and echo do the same thing in this scenario.