php点击文件链接进入index of,用php找到文本文件中的匹配链接

我有一个函数来读取文本文件,并与目录搜索进行交叉匹配,以将描述(文本文件)与文件的目录索引进行数学运算。我使用了leveltensin函数来给出一些模糊逻辑,所以名字不需要100%相同,但我遇到了一个障碍,因为我现在已经设置好了,因为当我取消注释行时在它下面搜索整个txt文件,并将每个单词与目录文件名进行比较。每700多个文件被检查700次,我很快就会耗尽内存。我需要一些方法来跳出while(!feof($ file_handle)),当它找到一个匹配,然后找到一些方法来设置下一个传递的起点到我们停止它的线位置,所以它不是循环0-700每一次

function GenerateList($titleB, $descB, $thumbB, $dirB, $patternB){

$outputB = "";

$open_error = 0;

if (is_dir($dirB)){

$myDirectory = opendir($dirB);

// get each entry

while($entryName = readdir($myDirectory)) {

$dirArray[] = $entryName;

}

// close directory

closedir($myDirectory);

// count elements in array

$indexCount = count($dirArray);

// sort em

sort($dirArray);

// loop through the array of files and print them all

if (!($text = file_get_contents("Scripts/descriptions.txt"))){$open_error = 1;}

$results = array();

for($index=0; $index < $indexCount; $index++) {

$ext = explode(".", $dirArray[$index]);

$parsed_title = preg_replace ($patternB, "", $ext[0]);

if ((substr("$dirArray[$index]", 0, 1) != ".")&&($ext[1] == "flv")){ // don't list hidden files

//if ($open_error == 0){

// $file_handle = fopen("Scripts/descriptions.txt", "rb");

//while (!feof($file_handle) ) {

//$line_of_text = fgets($file_handle);

//$parts = explode('|', $line_of_text);

/*

echo "

";

echo strtolower($parts[0]);

echo "";

echo strtolower($parsed_title);

echo "";

echo "

";

*/

//if ((wordMatch(strtolower($parts[0]), strtolower($parsed_title), 2)) > 0){

$outputB .= "";

$outputB .= "/Sources/Power Rangers/$dirB".$dirArray[$index]."";

$outputB .= "500";

$outputB .= "375";

$outputB .= "".$parsed_title."";

// $outputB .= "".$parts[1]."";

$outputB .= "test";

// $outputB .= "".$match_result[2]."";

$outputB .= "$thumbB";

// $outputB .= "".$match_result[3]."";

$outputB .= "$thumbB";

// $outputB .= "".$parts[4]."";

$outputB .= "true";

$outputB .= "";

//};//if ((wordMatch($parts[0], strtolower($word), 2) > 0)

//};//while

//fclose($file_handle);

//};//if ($open_error == 0)

};//if ((substr("$dirArray[$index]", 0, 1) != ".")&&($ext[1] == "flv"))

};//for($index=0; $index < $indexCount; $index++)

};//if (file_exists($dirB))

$outputB .= "";

return $outputB;

};//function

function wordMatch($words, $input, $sensitivity){

$shortest = -1;

foreach ($words as $word) {

$lev = levenshtein($input, $word);

if ($lev == 0) {

$closest = $word;

$shortest = 0;

break;

} //if

if ($lev <= $shortest || $shortest < 0) {

$closest = $word;

$shortest = $lev;

} //if

} //foreach

if($shortest <= $sensitivity){

return $closest;

} else {

return 0;

} //if/else

} // function, http://php.net/manual/en/function.levenshtein.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值