Home  >  Article  >  Backend Development  >  PHP determines whether remote article exists program code_PHP tutorial

PHP determines whether remote article exists program code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:07:23880browse

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630435.htmlTechArticleI 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, but, To save it correctly and accessible, although the customer did not ask for it, we still thought of this...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn