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
Share on other sites

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

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.