0

i need some help going line by line in a text file then making those lines the values for a drop down box, here is what i have got so far but i don't think this is close to correct. Any help would be great Thanks

  <?php 
    $filename = 'data/names.txt';
    $nameContents = file($filename);
    ?>

<form>
    <select id="value">
        <option selected value="base">Please Select</option>
        <?php foreach($nameContents as $line){  ?> <option"><?php $line ?></option> ?> <?php } ?>
    </select>
</div>
mattoakley
  • 11
  • 3

2 Answers2

1

you need to write echo $line

<option"><?php echo $line ?></option> ?>
Camilo Andres
  • 196
  • 1
  • 12
0

For anybody who see's this after, this is the working result i got.

<div>
<form>
    <select id="value">
        <option selected value="base">Please Select</option>
        <?php 
        foreach(file('data/names.txt') as $line) { ?>
            <option><?php echo $line ?></option>
        <?php } ?>

    </select>
</div>
mattoakley
  • 11
  • 3
  • which is basicly the same as @camiloAndres.... answer. There was nothing wrong with the file read (because you didn't really change that), but you only missed the echo – Jeff Jun 21 '18 at 23:03