Jump to content

[SOLVED] Need to create drop down box with data pulled from text file


mazman13

Recommended Posts

Trying to make a drop down box like this example:

 

Dog

Cat

Bird

 

But sometimes I will need to update it...and add/remove names from the list. I want to do it fast and easy and I don't want to use a MySQL Database. I'd rather use a text file...can that be done?

 

I would keep the info in a text file and then push it to a drop down box via php and html.

Let me know if this will work.

 

Link to comment
Share on other sites

Yes it will work.

 

Code would be something like this:

$text = file_get_contents("test.txt");
$array = explode("\n",$text);
echo "<select>";
foreach ($array as $value) {
echo "<option value='$value'>$value</option>";
}
echo "</select>";

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.