Hi All,
I have an issue trying to pull an array from a text file containing simple names on each line. The problem is that the foreach does not parse the array created by file() but does when I just created an array().
I have included the code below.
Anyone know how to get around this?
Thanks
Phil Dowson
---- contents of colors.txt ----
blue
yellow
red
---- contents of colors.txt ----
<?
//This creates the array, but doesnt work when parsed
$lines = file('colors.txt');
//This works great, but why doesnt file()
$lines = array('blue', 'yellow', 'red');
$test = "yellow";
//This should output the word yellow
foreach ($lines as $value) {
if($value == $test) {
echo $value."<br />\n";
}
}
?>