php file_get_contents() shows page instead of html source code

后端 未结 4 916
春和景丽
春和景丽 2021-01-03 09:42

I\'ve got this piece of code, which should fetch the source code of the website.

$homepage = file_get_contents(\'http://homepage.com\');
echo $homepage;
         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 10:27

    Either use htmlentities or change the content type.

    $homepage = file_get_contents('http://homepage.com');
    echo htmlentities($homepage);
    

    or

    header('Content-type: text/plain');
    $homepage = file_get_contents('http://homepage.com/');
    echo $homepage;
    

提交回复
热议问题