PHP100 excellent: PHP web snapshot generation

Source: Internet
Author: User
? Php $ url = 'www .baidu.com '; // capture Baidu echosnapshot ($ url); // The output result is the image address echosnapshot ($ url ,'. /baidu.png '); // save the image to baibaidu.png, and output the image size/*** generate a webpage snapshot * FrPHP100.

$ Url = 'www .baidu.com '; // capture Baidu
Echo snapshot ($ url); // The output result is the image address.
Echo snapshot ($ url, './baidu.png'); // save the image to baibaidu.png, and the image size of the output content.

/**
* Generate a web snapshot
* Fr PHP100.com Forum xiaokai
* @ Param string $ site destination address
* @ Param string $ path: save address. if it is null, it is not saved.
* @ Param integer $ dealy latency
* @ Return mixed return parameters
*/
Function snapshot ($ site, $ path = '', $ dealy = 0)
{
$ Url = 'http: // ppt. cc/yo2/catch. php ';
$ Query = 'url = '. $ site.' & delay = '. $ dealy.' & rnd = '. mt_rand (1, 9 );
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_POST, true );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ query );
Curl_setopt ($ ch, CURLOPT_USERAGENT, $ _ SERVER ['http _ USER_AGENT ']);
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
$ Data = curl_exec ($ ch );
Curl_close ($ ch );


If (strlen ($ data )! = 32 ){
Exit ('invalid website ');
}


$ File = $ data {0}. '/'. $ data {1}. '/'. $ data {2 }.'/';
$ File = 'http: // cache.ppt. cc/'. $ file. 'src _'. $ data. '.png ';


If (! Empty ($ path )){
$ Data = file_get_contents ($ file );
Return file_put_contents ($ path, $ data );
}
Return $ file;
}
 

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.