php如何从一个网址中获取到他所对应页面的html源代码?
phpcn_u238
phpcn_u238 2017-03-17 14:24:45
0
2
1032

我用file_get_contents($url);这个方法不行
`$url = $_POST['url'];
$ch = curl_init();
$timeout = 3;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;
exit;`
url是在前端输入的,我试过了,输入www.baidu.com,显示的仍是百度的界面,而不是他的html源代码

phpcn_u238
phpcn_u238

répondre à tous(2)
数据分析师

Comment php obtient-il le code source html de sa page correspondante à partir d'une URL ? - Questions et réponses sur le site Web PHP chinois - Comment php obtient-il le code source html de sa page correspondante à partir d'une URL ? - Questions et réponses sur le site Web PHP chinois

Jetez un oeil autour de vous , Étudiez-le.

阿神
<?php
 $pagecontent = file_get_contents("http://www.php.cn"); 
 echo htmlspecialchars($pagecontent);//htmlentities 或者htmlspecialchars
 ?>

这样就好了吧  你试试

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!