file_get_contents when url doesn't exist

前端 未结 8 2277
刺人心
刺人心 2020-12-01 02:37

I\'m using file_get_contents() to access a URL.

file_get_contents(\'http://somenotrealurl.com/notrealpage\');

If the URL is not real, it r

8条回答
  •  执念已碎
    2020-12-01 03:12

    You may add 'ignore_errors' => true to options:

    $options = array(
      'http' => array(
        'ignore_errors' => true,
        'header' => "Content-Type: application/json\r\n"
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents('http://example.com', false, $context);
    

    In that case you will be able to read a response from the server.

提交回复
热议问题