2013-10-28 1 views

답변

0

당신은 "바이트"다른 라인에 대한 모든 행을 비교하려면, 그래서 내가 할 것 :

$lines1 = file('file1.txt'); 
$lines2 = file('file2.txt'); 

$lookup = array(); 

foreach($lines1 as $line) { 
    $key = crc32($line); 
    if (!isset($lookup[$key])) $lookup[$key] = array(); 
    $lookup[$key][] = $line; 
} 

foreach($lines2 as $line) { 
    $key = crc32($line); 

    $found = false; 
    if (isset($lookup[$key])) { 
    foreach($lookup[$key] as $lookupLine) { 
     if (strcmp($lookupLine, $line) == 0) { 
     $found = true; 
     break; 
     } 
    } 
    } 

    // check if not found 
    if (!$found) { 
    // output to file or do something 
    } 
} 

참고 파일이 매우 큰 경우이 꽤 많은 메모리를 소비하는 것입니다 그리고 당신은 일부를 사용합니다 다른 메커니즘이지만 생각은 동일하게 유지됩니다