Page 1 of 1

Undefined variable is certainly defined

Posted: Fri Apr 06, 2012 5:24 am
by mads-hk
Greetings!

I have narrowed my problem down to this bit:

Code: Select all

<?php
$productgroupfile = file_get_contents("./product-groups.txt");
$productgroups = explode("\n",$productgroupfile);
foreach ($productgroups as $productgroup) {
	echo "<a href=\"link.html\">".$productgroup."</a> <br />";
}
?>
And it throws the following errors(line 13, is the line with the foreach loop):
Notice: Undefined variable: productgroups in /Applications/MAMP/htdocs/bau/product-groups.php on line 13

Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/bau/product-groups.php on line 13
The txt file contains:
product1
product2
product3
I have been staring at those five lines for at few hours, and i seriously can't figure out the problem... Maybe i have just missed a semi-colon or something, maybe im just blind!

Thanks in advance,

Mads

Re: Undefined variable is certainly defined

Posted: Fri Apr 06, 2012 6:47 am
by Celauran
Have you done a var_dump of $productgroups? Doesn't Mac use a different line end? \r or something?