Technology changes life--Movie catalog Check tool (PHP) _php tutorial

Source: Internet
Author: User

In this era of harmonious flooding, want to download a movie is so not easy, so I formed the habit of collecting movies, 2 1T hard disk collection of nearly 600 films, so many colleagues and friends know, have to borrow hard disk copy film, so the problem is coming ...

Because there is no hard drive lock, I have no control over whether they are "hands-on" to the hard drive, such as cutting by hand or accidentally deleting it. Although I have a TXT file dedicated to recording the movie directory, the following

  

But a check in the past, not only a waste of time, but also cause fatigue caused by leakage. In this case, why not use their own professional skills to achieve my needs, say, do it.

First, I'm going to read the movie catalogue from the TXT file and the PHP array.

$fp = fopen (' D:\movieList.txt ', ' R ');

for ($i =0; $i <562; $i + +) {

$arr [] = Trim (substr (fgets ($FP), 4));

}

Fclose ($FP);

Where 562 is the number of TXT file lines, because one movie I store a row. Because the 4 characters in the storage directory are the movie definition type, there are DVD, BD and MKV Three, so I use substr (fgets ($FP), 4) to remove the first 4 characters, and then use trim to remove the leading and trailing spaces, so that the final deposit into the array of the title does not contain any other characters.

Then to do is to read the movie directory under the mobile hard disk, here I am looking for a section of the Web folder to read the file name function

function Myreaddir ($dir) {

$handle = Opendir ($dir);

$i = 0;

while ($file =readdir ($handle)) {

if ($file! = ".") && ($file! = "...")) {

$list [$i] = $file;

$i = $i +1;

}

}

Closedir ($handle);

return $list;

}

$movie = Myreaddir ("I:\movies");

There is a flaw in this approach, that is, it is not possible to read files under sub-files, but it is enough for me to be able to expand on this basis.

And then it's the process of checking.

foreach ($arr as $v) {

$f = false;

foreach ($movie as $VV) {

if (Strstr ($VV, $v)! = "") {

$f = true;

}

}

if (! $f) {

echo $v. "
";

}

}

The core method of checking is to determine if the string a contains the string B, that is, whether the movie file name contains the film name in the movie directory, or if it is not included, the output.

After testing the correct rate is basically 80%, but there is a bug, such as my movie catalogue has a movie called "Chainsaw", but my folder does not have "chainsaw 1024*768.rmvb", and there is a part called "Saw 1024*768.rmvb", so the procedure is judged through.

The only solution is to record the movie directory when the full file name is recorded, do not just record "chainsaw", but should record "chainsaw 1024x768", or simply record the file format, so that when checking, you can directly do string comparison.

If there is a better solution, please let me know.

Original address: http://www.cnblogs.com/hooray/archive/2011/10/30/2228990.html

http://www.bkjia.com/PHPjc/478554.html www.bkjia.com true http://www.bkjia.com/PHPjc/478554.html techarticle in this era of harmonious flooding, want to download a movie is so difficult, so I formed the habit of collecting movies, 2 1T hard disk collection of nearly 600 films, so many colleagues ...

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