How can I check if a URL exists via PHP?

前端 未结 22 1677
天涯浪人
天涯浪人 2020-11-22 04:13

How do I check if a URL exists (not 404) in PHP?

22条回答
  •  梦如初夏
    2020-11-22 05:01

    function url_exists($url) {
        $headers = @get_headers($url);
        return (strpos($headers[0],'200')===false)? false:true;
    }
    

提交回复
热议问题