日期:2014-05-17 浏览次数:20642 次
function w($cont, $filename) {
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "不能打开文件 $filename";
exit;
}
if (fwrite($handle, $cont) === FALSE) {
echo "不能写入到文件 $filename";
exit;
}
echo "成功地将 $somecontent 写入到文件$filename";
fclose($handle);
} else {
echo "文件 $filename 不可写";
}
}
$cont_a = file_get_contents("/path/filenameA");
$arrA = explode("\n", $cont_a);
$cont_b = file_get_contents("/path/filenameB");
$arrB = explode("\n", $cont_b);
$arrNewB = array_diff($arrB, $arrA);
$cont_newb = implode("\n", $arrNewB);
$arrC = array_diff($arrA, $arrB);
$cont_c = implode("\n", $arrC);
w($cont_newb);
w($cont_c);
------解决方案--------------------
貌似array_diff函数 + file函数就行了,LZ试下效率如何。