PHP load array from file foreach

jKun

New Member
I have this code:\[code\]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);\[/code\]And instead of \[code\]$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);\[/code\]I want to implement \[code\]$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);\[/code\]now the result.txt doesnt gets written anymore, where do i go wrong?the script should read an array from a file, process the function hot and then write each reasults in a new line in result.txtthanks in advance!
 
Back
Top