我有這樣的代碼:PHP負載陣列
require("class.XMLHttpRequest.php");
function hot($news){
$url="https://localhost/search.aspx?search=".$news."";
$ajax=new XMLHttpRequest();
$ajax->setRequestHeader("Cookie","Cookie: host");
$ajax->open("GET",$url,true);
$ajax->send(null);
if($ajax->status==200){
$rHeader=$ajax->getResponseHeader("Set-Cookie");
if(substr_count($rHeader, "Present!")>0) { return true; }
}else{ return false; }
}
$celebrities = array('britney','gaga','carol');
$filename = 'result.txt';
$handle = fopen($filename, 'a');
foreach($celebrities as $celebrity)
{
if(hot($celebrity)) { fwrite($handle, "{$celebrity}\r\n"); };
}
fclose($handle);
代替
$celebrities = array('britney','gaga','carol');
$filename = 'result.txt';
$handle = fopen($filename, 'a');
foreach($celebrities as $celebrity)
{
if(hot($celebrity)) { fwrite($handle, "{$celebrity}\r\n"); };
}
fclose($handle);
我想要實現
$read_file = fopen('array.txt', 'r');
$write_file = fopen('result.txt', 'a');
while(!feof($read_file))
{
$celebrity = fgets($read_file);
if(hot($celebrity)) { fwrite($handle, "{$celebrity}\r\n"); }
}
fclose($write_file);
fclose($read_file);
現在的Result.txt犯規被寫入和現在,我哪裏出錯了? 腳本應該從一個文件中讀取一個數組,然後處理該函數,然後將每個重新寫入的結果寫在result.txt中的新行中 在此先感謝!
感謝,它的工作 – adam 2010-09-30 15:59:36