View Full Version : Why does this error occur ?

12-31-2003, 12:37 AM
$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 ?

12-31-2003, 12:48 AM
I suppose that $lines2 is a string and not an array. Foreach() iterates an array.

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

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


$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.