What is the best way to check if a URL exists in PHP?
问题 What is the best way to see a URL exists and the response is not a 404 ? 回答1: You can use get_headers($url) Example 2 from Manual: <?php // By default get_headers uses a GET request to fetch the headers. If you // want to send a HEAD request instead, you can do so using a stream context: stream_context_set_default( array( 'http' => array( 'method' => 'HEAD' ) ) ); print_r(get_headers('http://example.com')); // gives Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 29 May 2004 12:28:14 GMT