Help with Array Weirdness
| From: | Nick Wilson | Date: | Sun, 26 Sep 2004 22:59:11 +0000 |
| Subject: | Help with Array Weirdness | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-197915@lists.php.net to get a copy of this message | ||
well, ok, it's prolly my weirdness ;-)
Below is a little code that's very easy to understand. I've been messing
with it for hours and the problem must be really stupid cos i just cant
work it out (cant see the wood for the trees...)
<?php
$urls2filter=array(
"http://www.somesite.com/somepage.html",
"http://someothersite.com/somepage.html?id=5",
"http://www.myarse.com/index.html"
);
$uniqueHosts=array(
"www.somesite.com",
"someothersite.com"
);
foreach($urls2filter as $url) {
$parsedUrl=parse_url($url);
if(!in_array($parsedUrl['host'], $uniqueHosts)) {
$f = fopen('hosts2.txt', 'a');
fwrite($f, $parsedUrl['host']);
fclose($f);
$f = fopen('b.txt', 'a');
fwrite($f, $url);
fclose($f);
}
}
print("all done");
?>
if the 'host' part of the $urls2filter is NOT in the $uniqueHosts
array it should write the url to a file. It does not do this. And im
pulling what little hair i have out.
Can anyone see what godawful dumb mistake im making?
Much thanks...
--
Nick W