How to see the serial _php tutorial

Source: Internet
Author: User

Issue background

I am a fire fan, so every Wednesday, always to wait for the fire shadow updates constantly refresh the page. Later, I was fascinated by a serial novel, not regularly updated every day, so every day in there brush ah brush, F5 are almost rotten. F5 Rotten It doesn't matter, program ape so busy, how can precious time wasted in this place >_< wait until Thursday to see the fire shadow not on the line, every two days to see a novel not on the line, but, Minister concubine do not ah t.t

The scheme of obscenity

In order to avoid a few serial and day and night, as a can save the world of Technology house, of course, to do something >_< Yes, let the machine to automatically help me detect updates on the line. So, I just write a program, regularly read the contents of the serial directory, if detected updates, you can automatically send an email to my QQ mailbox reminds me to see the serial y^o^y

Implementation brief

The first is to simplify our problem, the above mentioned solution within the program, can be divided into the following sections:

    • Timed execution
    • Read the contents of the serial directory
    • Detect if there is an update
    • Send e-mail

By the way, I recently done PHP more, so the development of the language is based on PHP ╮ (╯_╰) ╭

The following is a simple description of the technical solution, after all, the program is also very simple to do, there is no magic code

Timed Execution-Crontab

I just rented a very dwarfish toy Linux Server A while ago, so I can keep the program running for 24 hours on this server. In a Linux system, timed execution can usually add a timed task via the crontab command. For example, I want to set up every 10 minutes, so the crontab additions are in the following format:

*/10 * * * *  /path/task.sh

Read the contents of the serial directory

The serial directory is on a Web page, to read out the contents of the directory, but also need to decompose the problem:

    • Download Web page
    • Analyze Web page Content

Download page-Curl

The content of a Web page is generally obtained from the server as a client via the HTTP protocol. In our scenario, the program we want to write will need to act as a client for HTTP protocol communication to download the data from the Web page, and you should think of the Curl Command line tool, which you can do with the EXEC function provided by PHP, or use PHP's own curl Library.

I'm using the PHP Curl Library and I'm interested in knowing it.

Analyzing the contents of a Web page-regular expressions

Downloaded to the Web page document is HTML code, in my view of the Naruto, for example, Http://www.mangapanda.com/93/naruto.html, (PS: not understand Japanese and English version of the update faster than the Chinese version of the faster, so ... )

For us, the serial directory is actually the element in the HTML document that has the HREF attribute value "/naruto/xxx".

As long as the download to the HTML code with a simple pattern matching to do text filtering, you can get the contents of the serial directory, I think you should also want to use the regular expression to do this thing is not suitable. In the case of the Web page just now, you can use the following line of regular expressions to roughly filter out the serial directory:

|href= "/naruto/[^"]* "|

Because different regular expressions are used differently, this regular expression should be configured by the user.

In PHP, you can use the Pregmatchall function in PHP PCRE Functions.

Detect if there is an update

This is relatively simple, only updates, then the serialization of the content will be bound to change. So as long as each read to the serial directory and the last read the content of the serial directory to compare, as long as there is a difference, it is determined that there is an update.

As for the storage of historical data, a file is available. I've made a fuss of using the MySQL database to do it.

e-mail-Phpmailer

I am not familiar with the computer network of e-mail protocol Understanding is also a mess, after Google, found the Phpmailer library, refer to this library provides examples of SMTP.

I use a QQ mailbox as the sender, the problem is to pay attention to this QQ mail to open the SMTP service.

Performance demos and Code downloads

Given the user-friendliness and versatility, a simple configuration page was made, as shown in:

The content of the reminder email is also very simple, the content is empty, but it is best to attach the serial directory link.

The code can be checked out using SVN:

SVN checkout "Https://svn.code.sf.net/p/roxma-proj/code/php_learn"

This is mixed with some of the accumulation of personal learning process and the theme of unrelated code, I believe there should be no one want to seriously, if you really want to see, you can go from phplearn/apps/seriesupdate_remindder/check.php. The code really does not recommend a closer look, I think the most important thing is actually "technical summary" in that section of the idea, (well code is too ugly you tell me secretly do not keep quiet)

http://www.bkjia.com/PHPjc/818579.html www.bkjia.com true http://www.bkjia.com/PHPjc/818579.html techarticle The problem is that I'm a fan of fire, so every Wednesday, there's always a time to refresh the page to keep up with the fire-shadow updates. Later, I was fascinated by a serial novel, Every day and more ...

  • 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.