checking array
| From: | joe | Date: | Sat, 15 Mar 2003 23:50:10 +0000 |
| Subject: | checking array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-139817@lists.php.net to get a copy of this message | ||
what is the best way to check, if a value is NOT in an array?
the purpose is to take results from a webpage and check one-by-one if they
are in the txt file already. if they are not, i have to write them there..
If they are in there then i just want to leave them alone.
this is what i came up with so far:
<?php
$fp = fopen ('http://site.com', 'r');
for ($src = ''; !feof ($fp); $src .= fgets ($fp, 1024));
fclose ($fp);
preg_match_all ('/\<td\>(.*)\<\/td\>/isU', $src, $sum, PREG_SET_ORDER);
$i=0;
$result=file('boot.txt');
while($sum[$i][1] && $i<50){
$word=$sum[$i][1];
if(in_array($word, $result)){}
else{
$word = "\n".$word;
$addtxt = fopen('boot.txt', 'a');
fputs($addtxt,$word);
fclose($addtxt);
}
$i++;
}
?>
but somehow it still writes into the txtfile if if an identical line is
already there.
could somebody please correct the code or suggest a better option for
checking?
thank you