$tab=array(); $tabA = explode("\n",file_get_contents("A.txt"); $tabB = explode("\n",file_get_contents("B.txt"); foreach($tabA as $i => $row) { $tabtmpA = explode(";",$row); if(in_array($tabtmpA[2],$tabB)) $tab[] = $row; } $str = implode("\n",$tab); file_put_contents($str,"fichier.txt");