PHP Thief Program Design and implementation of detailed _php skills

Source: Internet
Author: User
Tags create directory curl php programming php regular expression

This article describes the PHP Thief program Design and implementation methods. Share to everyone for your reference, specific as follows:

In fact, I have always wanted to do a connotation of the image of the site, the previous idea is to do a CMS, and then upload some pictures of their own.

The first thing to do is to have no motivation. Then gave up, then studied a curl. Anyway, it is better to achieve this idea.

Using PHP to steal pictures is like wearing sandals in socks. It's no problem, but it does hurt.

Let me first say my PHP thief program design, PHP does not support multithreading, so you can only do in a sequential order

Get to the target site HTML page + parse HTML page get to picture storage connection + read in binary mode and save locally + rename = = Process OK

You are now running the program in two different ways:

The first kind: Use the tour to run the program (most will be stuck to death, set timeout and memory size on OK, you are more difficult between)

Another: Start php with the command line (no problem with PHP timeout)

/** *html parsing class *author:summer *date:2014-08-22 **/class analytical{Public function __construct () {require_once
     (' class/simplehtmldom.class.php ');
  $this->_getdir (); Private Function _getdir () {$dir = ".
    /TMP/HTML/RESULTS/1 "; $imgBIG = ".
    /tmp/img/jpg/big "; $it = new Directoryiterator ($dir.)
    /"); foreach ($it as $file) {//filter out "." With the Isdot () method respectively. and ".." Directory if (! $it->isdot ()) {$dirs = $dir. "
       /". $file;
       $tmp = Explode (".", $file);
       $html = file_get_html ($dirs);
       $ULARR = $html->find (' img ');  foreach ($ulArr as $key => $value) {if ($value->class = = "U") {$url =http://www.jb51.net. $value->src; $infomation = file_get_contents ($url); $result = $this->savehtml ($infomation, $imgBIG, $tmp [' 0]. ". JPG "); if ($result) {echo $file. " Ok\n "; The Private function savehtml ($infomation, $filedir, $filename) {if (! $this)}}}}} ; mkdirs ($filedir)) {return 0; } $SF = $filedir. " /". $filename; $FP =fopen ($SF, "w"); Write way Open file return fwrite ($fp, $infomation); Deposit Content fclose ($FP); Close file}//Create directory Private Function mkdirs ($dir) {if (!is_dir ($dir)) {if (! $this->mkdirs Dirn Ame ($dir))) {return false; } if (!mkdir ($dir, 0777)) {return false; } return true; } new analytical (); 
The above

is the process by which an HTML page acquires an IMG connection address.

uses two more important things:

1.PHP Dom resolution extension simplehtmldom

2.PHP Directory iterator The

understands these two things. There is no difficulty with this analytic class.

Is talking about getting the page you want to parse? The

is actually the same as the above principle. Main gets the URL of the page, and then through Curl to read the page, return an HTML string,

and save the Function package HTML page saved to the local.

I am here because I want to capture the picture inside the page (in order to prevent other people's anti-theft chain), so the design is more complex. The

And why it is separated is because the Simplehtmldom object is large, and it is more clear that the process is disassembled.

Surely someone would say, why don't you just skip the HTML and save it to the local part, bingo! I can only bother to write the regular.

More interested readers of PHP-related content can view the site topics: "Php Curl Usage Summary", "PHP graphics and pictures Operating skills summary", "PHP Array" operation Techniques Daquan, "PHP common traversal algorithm and skills summary", " PHP Data structure and algorithm tutorial, "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP Common database Operation tips Summary"

I hope this article will help you with the PHP program design.

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.