This is driving me nuts. Take a look at this code:
<?php
$foo = file_get_contents('list.txt');
$jobs = array('one','two','three');
?>
<select>
<?php foreach($jobs as $key):?>
<option value='<?php echo $key; ?>'><?php echo $key; ?></option>
<?php endforeach; ?>
</select>
Simple right? It creates a drop down list of jobs, values are one, two, three.
Now...take those same values, but this time we're reading them from a text file:
<?php
$foo = file_get_contents('list.txt');
$jobs = array($foo);
?>
<select>
<?php foreach($jobs as $key):?>
<option value='<?php echo $key; ?>'><?php echo $key; ?></option>
<?php endforeach; ?>
</select>
View the source and you'll see the problem. reading the file into the array doesn't break apart the individual values. It's as if the $jobs array doesn't see the single quotes and commas separaring the array values!
I've spent hours on this. Can anyone advise what the deal is here?
Regards,
Matt