Home > Article > Backend Development > PHP determines whether remote article exists program code_PHP tutorial
I had a sudden thought today. When I was writing a case for a client, there was a place where netizens were asked to fill in the URL. However, the URL must be saved correctly and accessible. Although the client did not ask for it, we still thought of doing this. Just use PHP's file_get_contents and ob_get_contents() to read the remote article content. If it exists, it is true, otherwise it is false. Here are two examples I gave. Regarding ob_get_contents(), we need to modify several places in php.ini In front of the place that starts with curl_; if you go there, it will be OK.
$url='http://www.111cn.cn';
if(@file_get_contents($url)){
echo 'ture';
}else{
echo 'false';
}
if(getcontent($url) ){
echo 'ob_ture';
}else{
echo 'ob_false';
}
function getcontent($url){
$ch =curl_init($url);
ob_start();
curl_exec ($ch);
$retmsg=ob_get_contents();
ob_clean();
ob_end_flush();
curl_close ($ch);
return $retmsg;
}
?>
Statement: Please indicate the source when reprinting original articles on this site www.111cn.cn/phper/php.html