Jump to content

drop down link to .txt


t_k_eoh

Recommended Posts

Hi all,

 

I would really like to know how to link the contents from the .txt to be listed into drop down for users to select.

 

Eg. Inside my "data.txt", I have a few words:

Apple

Orange

Strawberry

 

I would like to recall out them to be listed into the drop down from my form. Is there any way this can be done??

Pls help. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/64870-drop-down-link-to-txt/
Share on other sites

<?php

$Filename = 'data.txt';

if (file_exists($Filename) && is_readable($Filename))
{
    $Links = file($Filename);
    
    echo '<select name="">';
    foreach ($Links as $Link)
    {
        echo "<option value='$Link'>$Link</option>";
    }
    echo '</select>';
}

?>

 

Try:

<?php
$f = fopen("data.txt", "r");
echo "<select name='fruits'>";
while($line = fgets($f)) echo "<option value='$line'>$line</option>";
echo "</select>";
fclose($f);
?>

 

Hope that helps.

[edit] Hehe... mine is shorter than the below post ;D

[edit] Hehe.... mine is more practical than the above post  ;D

Link to comment
https://forums.phpfreaks.com/topic/64870-drop-down-link-to-txt/#findComment-323676
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.