PHP ini file_get_contents external url

后端 未结 7 1912
攒了一身酷
攒了一身酷 2020-11-22 15:28

I use following PHP function:

file_get_contents(\'http://example.com\');

Whenever I do this on a certain server, the result is empty. When I do

7条回答
  •  梦谈多话
    2020-11-22 15:55

    Complementing Aillyn's answer, you could use a function like the one below to mimic the behavior of file_get_contents:

    function get_content($URL){
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_URL, $URL);
          $data = curl_exec($ch);
          curl_close($ch);
          return $data;
    }
    
    echo get_content('http://example.com');
    

提交回复
热议问题