How do I include an external file in PHP?

前端 未结 2 742
太阳男子
太阳男子 2021-01-06 14:47

I need to include and external file that is on another url. For example google.com. I have tested the include using local files, so that much works, but if I try and use 127

2条回答
  •  独厮守ぢ
    2021-01-06 15:37

    You'll need to use file_get_contents:

    $data = file_get_contents('http://google.com'); //will block
    

    Or fopen:

    $fp = fopen('http://google.com', 'r');
    $data = '';
    while(!feof($fp)) 
       $data .= fread($fp, 4092); 
    fclose($fp); 
    
    echo $data;
    

提交回复
热议问题