0
<?php
//reference text
foreach (glob("file1.txt") as $filename1) {
$file1 = $filename1;
$line1 = rtrim($file1, "\n");
$contents1 = file($line1, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$string1 = implode($contents1); // file_put_contents('google.txt',implode('',$contents1));
$array1 = str_split ($string1);
$temp = $array1;
}
//fetch from website
$url ="https://www.example.com/";
$str = file_get_contents($url);
$myFile = "file2.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $str;
fwrite($fh,$stringData);
fclose($fh);
foreach (glob("fetch_hLeong.txt") as $filename) {
$file = $filename;
$line = rtrim($file, "\n");
$contents = file($line,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$string = implode($contents);
$array = str_split($string);
$temp1 = $array;
//比較 $結果和array_diff_assoc =($溫度,$ temp1目錄); if(!count($ result)) echo「
File => MATCH」; else echo「
File => NOT MATCH」;
?>
所以我有這種類型的代碼,我去比較這些FILE1.TXT和FILE2.TXT。 在這裏,我把文字文件中的每個字符放到一個數組中,並且我將它逐個字符地進行比較。 所以我的問題是,比較代碼顯示不匹配,實際上它匹配。 www.example.com的新聞提要每秒都會改變,因爲我的文件顯示不匹配。
我想刪除某些字符串,它是file1.txt中的新聞源,以便它不會影響進程。任何人 ??謝謝你的幫助 。
爲什麼'glob()'在那裏? – alex 2011-03-28 02:40:07
使我更容易得到文本文件。 – lesta 2011-03-28 02:50:48
你關心文件是如何不同的,或只是它們是? – 2011-03-28 02:55:25