t_k_eoh Posted August 14, 2007 Share Posted August 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64870-drop-down-link-to-txt/ Share on other sites More sharing options...
php_tom Posted August 14, 2007 Share Posted August 14, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/64870-drop-down-link-to-txt/#findComment-323671 Share on other sites More sharing options...
hostfreak Posted August 14, 2007 Share Posted August 14, 2007 <?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 [edit] Hehe.... mine is more practical than the above post Quote Link to comment https://forums.phpfreaks.com/topic/64870-drop-down-link-to-txt/#findComment-323676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.