首页 课程 师资 教程 报名

PHP从URL获取HTML代码

  • 2022-02-16 09:39:51
  • 939次 星辉

从任何网站获取他的 html 源代码都很容易。您可以通过 php.ini 的功能非常轻松地做到这一点。我会告诉你 3 种 获取 html 源代码的方法。

解决方案1:

<?php 
$data = file_get_contents("https://www.lipsum.com/");
$html_sourcecode_get = htmlentities($data);
echo $html_sourcecode_get;
?>
 

解决方案2:

<?php 
$data = file_get_contents('https://www.lipsum.com/');
echo htmlspecialchars($data);
?>

解决方案3:

<?php 
$u = "https://www.lipsum.com/";
$ch = curl_init($u);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$newquery = curl_exec($ch);
echo $newquery_get = htmlentities($newquery);
?>

 

选你想看

你适合学Java吗?4大专业测评方法

代码逻辑 吸收能力 技术学习能力 综合素质

先测评确定适合在学习

在线申请免费测试名额
价值1998元实验班免费学
姓名
手机
提交