Home php教程 php手册 技术改变生活电影目录核对工具(php)

技术改变生活电影目录核对工具(php)

Jun 13, 2016 am 10:45 AM
php download No harmonious exist tool technology Change yes Life Movie of Table of contents this

 

 

 

在这个和谐泛滥的年代,想下载一部电影是如此的不容易,于是我就养成了收藏电影的习惯,2个1T的硬盘收藏了近600部片子,于是很多同事朋友知道后,纷纷向我借硬盘拷电影,于是问题也就来了……

  因为没有硬盘锁,所以我无法控制他们对硬盘是否“动手脚”,比如手误造成的剪切或者误删。虽然我有专门一个记录电影目录的txt文件,如下

  

 

但要一个一个核对过去,不仅浪费时间,而且会造成疲劳导致漏看。既然如此,何不用自己的专业技能来实现我的需求呢,说干就干吧。

 

  首先我要把电影目录从txt文件里读取出来并存为php数组

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

for($i=0; $i

    $arr[] = trim(substr(fgets($fp),4));

}

fclose($fp);

  其中562是txt文件行数,因为一部电影我就存放一行。因为存放目录里头4个字符是影片清晰度类型,有DVD、BD和MKV三个,所以我用substr(fgets($fp),4)去掉头4个字符,然后用trim去掉首尾的空格,这样最终存放到数组里的片名就不包含任何其他字符了。

  然后要做的就是读取移动硬盘下的电影目录,这里我找的是一段网上读取文件夹下文件名的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");

  这个方法有一个缺陷,就是不能读取子文件下的文件,不过对于我来说已经足够了,大家有兴趣可以在这基础上扩展下去。

  然后就是核对的过程

foreach($arr as $v){

    $f = false;

    foreach($movie as $vv){

        if(strstr($vv,$v)!=""){

            $f = true;

        }

    }

    if(!$f){

        echo $v."
";

    }

}

  核对的核心方法就是判断字符串A里是否包含字符串B,也就是电影文件名里是否包含电影目录里的片名,如果不包含,则输出。

  测试后正确率基本有80%,但有一个bug,比如我的电影目录里有部电影叫“电锯”,但是我文件夹里没有“电锯1024*768.rmvb”,而有部叫“电锯惊魂1024*768.rmvb”的,这样程序是判断通过的。

  唯一的解决办法就是在记录电影目录的时候,就把完整的文件名记录下来,不要只记录“电锯”,而应该记录“电锯1024*768”,或者干脆把文件格式也记录下来,这样在核对的时候,可以直接进行字符串比较。

  如果有更好的解决办法,欢迎告诉我。

 

原文地址:http://www.cnblogs.com/hooray/archive/2011/10/30/2228990.html

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Does H5 page production require continuous maintenance? Does H5 page production require continuous maintenance? Apr 05, 2025 pm 11:27 PM

The H5 page needs to be maintained continuously, because of factors such as code vulnerabilities, browser compatibility, performance optimization, security updates and user experience improvements. Effective maintenance methods include establishing a complete testing system, using version control tools, regularly monitoring page performance, collecting user feedback and formulating maintenance plans.

Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Apr 06, 2025 am 12:07 AM

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

How can you prevent a class from being extended or a method from being overridden in PHP? (final keyword) How can you prevent a class from being extended or a method from being overridden in PHP? (final keyword) Apr 08, 2025 am 12:03 AM

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

Why does negative margins not take effect in some cases? How to solve this problem? Why does negative margins not take effect in some cases? How to solve this problem? Apr 05, 2025 pm 10:18 PM

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

Explain strict types (declare(strict_types=1);) in PHP. Explain strict types (declare(strict_types=1);) in PHP. Apr 07, 2025 am 12:05 AM

Strict types in PHP are enabled by adding declare(strict_types=1); at the top of the file. 1) It forces type checking of function parameters and return values ​​to prevent implicit type conversion. 2) Using strict types can improve the reliability and predictability of the code, reduce bugs, and improve maintainability and readability.

See all articles