Php to determine whether a remote article has a program code _ PHP Tutorial

Source: Internet
Author: User
Php checks whether remote articles have program code. Today's whimsy, when I wrote a case for a customer, there was a place where users were asked to enter a url. however, to save the case, it was correct and accessible, although the customer did not ask for it, we still think of such a strange idea today. when I wrote a case for a customer, there was a place where the user was asked to fill in the url. However, the storage is correct and accessible. although the customer does not require it, we still want to do so by reading the remote article content using file_get_contents and ob_get_contents () of php, if there is one, it will be false. Here are the two instances I mentioned. for information about ob_get_contents (), we will go to php. in ini, modify the prefix of curl.

$ 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;

}
?>

Declaration: for original articles on this site, please refer to www.111cn.cn/phper/php.html

Sorry, when I write a case to a customer, there is a place where users are required to fill in the url, but it is correct and accessible to save it, although the customer didn't ask for it, we still thought of this...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.