donglei2288 2015-07-19 04:17
浏览 58

PHP如何处理大量的时间

I have a 36mb (FILE B) with over 650k lines.I have tried fgets, fopen, file_get_contents and they are not working. I think I am running out of memory. What I am trying to do is, I have file 'A excel (138 lines)', I want to loop thru it get a value and go find (via regex )it in File B (.TXT - 35MB). Once I have found it in 'File B' , I want to take it write it in 'FILE A'. I went into the .ini changed max memory also and the timer (300). fopen() sample below:

$handle = fopen("/Users/jerry/Desktop/info.TXT", "r") or die("Couldn't get handle");
if ($handle) { //IF
    while (!feof($handle)) { //WHILE
        $buffer = fgets($handle, 4096);
        //  echo $buffer; //displays the 650k lines
         for ($row12 = 2; $row12 <= 23; $row12++){ //for1
$name3 = $objPHPExcel45->getActiveSheet()->getCellByColumnAndRow(3, $row12)->getValue() ; 
            $regex144 = "/$name3/";
            preg_match($regex144, $buffer, $try);
            foreach ($try as $h => $wer){//foreach
                echo $wer; echo $row1; echo "<br>";
        //  $nameset = $objPHPExcel45->getActiveSheet()->setCellByColumnAndRow(7, $row12)->getValue() ;
            }//foreach
        }//for 1    
    }//WHILE    
    fclose($handle);
}//IF

File_get_contents option:

$htmlfile = "/Users/deepak/Desktop/info.TXT";
$html1 = file_get_contents($htmlfile);
for ($row3 = 2; $row3 <= 50; $row3++){ 

      $name3 = $objPHPExcel45->getActiveSheet()->getCellByColumnAndRow(3, $row3)->getValue() ; 
//checking for a initial 
        if (preg_match($renamewithinitials, $name3, $matchesini)) { //1st if

    //flip the name with initials
$names5 = explode(" ", $name3);
$name5 = $names5[2] . " " . $names5[1]. " " . $names5[0];   
$length1 = strlen($name5);
$regex1 = "/[0-9]{23}$name5/";
preg_match($regex1, $html1, $t);
foreach($t as $x22 => $x_value22) {
    echo "lets see if works LION INITIAL: $x_value22"; echo "<br>";
}

//set in excel under a new column 'flip name'
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3,$name5);
} //1st if

  // is there a compnay name
     else { //1st else
        if (preg_match($renamewithinitials2, $name3, $matchesini2)) { //2nd if

//NO name flipping
$name6 = $name3;
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3, $name6);
        } //2nd if


     //is there 2 spaces TWO SPACES TWO SPACES ONLY
        else { //2nd else
        if (preg_match($renamewithTwoSpaces, $name3, $matchesini3)) {//3rd if
        //flip name
            $names8 = explode("  ", $name3);
$name8 = $names8[1] . " " . $names8[0];

$regextwospace = "/[0-9]{23}$name8/";

preg_match($regextwospace, $html1, $t2space);
foreach($t2space as $x2234 => $x_value2234) {
    }
//set in excel under a new column 'flip name'
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3, $name8);
        }//3rd if   
        //is there ONE SPACE ONE SPACE ONLY
        else { //3rd else
        if (preg_match($renamewithOneSpace, $name3, $matchesini4)) { //4th if
        //flip name
            $names9 = explode(" ", $name3);
$name9 = $names9[1] . " " . $names9[0];
$regexonespace = "/[0-9]{23}$name9/";
preg_match($regexonespace, $html1, $tonespace);
foreach($tonespace as $x223 => $x_value223) {
}
//set in excel under a new column 'flip name'
//$objPHPExcel->getSheet(0)->SetCellValueByColumnAndRow(6, $row3, $name9);
        }//4th if
        } //2nd else

                        }  //3rd else   
            } //1st else    
}  //for     
//}
fclose($html1);
//we save
$objWriter45->save($auctionFileExplodeFinal[0].'-DRD-FILE-copy-nosave.xlsx');
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 用三极管设计—个共射极放大电路
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示