PHP dropdown selection

How can i code php dropdown form to select values from a .txt file?

Comments

  • You can use file_get_contents to read the file. Then loop each line and create an option tag for it.
  • Text File :
    [COLOR="DarkOrchid"][B]options.txt[/B][/COLOR]
    
    Option1
    Option2
    Option3
    

    PHP File :
    [COLOR="Blue"][B]<?php
    	$file = fopen("option.txt", "r") or exit("Unable to open file!");
    	//Output a line of the file until the end is reached
    	echo "<select>";
    	while(!feof($file))
    	  {
    		$line=fgets($file);
    	  	echo"/n<option value='$line'>$line</option>";
    	  };
    	  echo "</select>";
    	fclose($file);
    
    ?>[/B][/COLOR]
    
Sign In or Register to comment.