RE: [PHP] checking array
| From: | Ford, Mike [LSS] | Date: | Mon, 17 Mar 2003 13:30:12 +0000 |
| Subject: | RE: [PHP] checking array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-139950@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: joe [mailto:liberache@hot.ee]
> Sent: 15 March 2003 23:50
>
> 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');
Well the manual entry for file() (http://www.php.net/file) says that the
array created still has the newline attached to the end of each entry, so...
> while($sum[$i][1] && $i<50){
> $word=$sum[$i][1];
> if(in_array($word, $result)){}
... this won't work unless you also have a newline at the end of $word -- if
you don't, you may have to do something like:
if(!in_array($word."\n", $result))
{
$word = "\n".$word;
// etc
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211