PHP100 excellent: PHP web snapshot generation _ PHP Tutorial

Source: Internet
Author: User
PHP100 tips: PHP generates web page snapshots .? Outputs: Output Content image $ 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 size of the output image

/**
* Generate a web snapshot
* Fr bkJia.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 URL );
}


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

Http://www.bkjia.com/PHPjc/508433.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508433.htmlTechArticle? Php $ 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 output the content image...

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.