...

View Full Version : Why does this error occur ?



Richard
12-30-2003, 11:37 PM
<?
$lines = file('http://www.url.com');
$lines2 = strip_tags($lines);

foreach ($lines2 as $line) { echo $line; }
?>


Warning: Invalid argument supplied for foreach() in /home/domains/domain/user/htdocs/page.php on line 5

Why ?

raf
12-30-2003, 11:48 PM
I suppose that $lines2 is a string and not an array. Foreach() iterates an array.

SDP2006
12-30-2003, 11:54 PM
Yes, $lines2 is just a plain ole' variable. Foreach is used with arrays and that is not an array.

ReadMe.txt
12-31-2003, 04:50 PM
$lines = file('http://www.url.com');
foreach ($lines as $line) { echo strip_tags($line); }


or



$file = file_get_contents('http://www.url.com');
echo $file;


or if you still need to parse line by line (for numbering perhaps)



$file = file_get_contents('http://www.url.com');
$lines = explode("\n",str_replace("\r",'',$file));
//the str_replace sorts out windows linebreaks

foreach ($lines as $line) {
echo $line."\n"; //the \n is important as explode strips the line breaks
}


There ya go, one of them should be what you need.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum