hotrod57 Posted October 24, 2007 Share Posted October 24, 2007 am using php to write a function that reads in lines from a text file and creates a form with the corresponding input values. I have a text file that looks like this: title = Test Page checkbox = shoe checkbox = comb I can separate these lines into an array, ($array[0] = title, checkbox, checkbox, and $array[1] = Test Page, shoe, comb) but I can't seem to figure out how to get the function to print out each array with its value. For example: if my function reads the line "checkbox = shoe", I have the statement print ("<input type=checkbox name=userbox value=$check>$check");, which should print a checkbox on a form with its value being shoe. While testing, I got it to do that once, but it would only print out a checkbox with shoe like a million times on the page and never stop. It never reads the next line to see what the input will be. I tried to correct this, and now I can't even get it to print that out again. If anybody could help or show me where to get some help, it would be greatly appreciated. Here is where my code acts up: <?php $data = file('test_read.txt'); $line = explode("=", $data[1]); while ($line[0] == 'checkbox'){ $check = $line[1]; print ("<input type=checkbox name=userbox value=$check>$check"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74642-using-php-to-create-a-form-from-a-text-file/ Share on other sites More sharing options...
sKunKbad Posted October 24, 2007 Share Posted October 24, 2007 You are going to have to loop through the array and then output your checkboxes for each checkbox array value. Quote Link to comment https://forums.phpfreaks.com/topic/74642-using-php-to-create-a-form-from-a-text-file/#findComment-377299 Share on other sites More sharing options...
only one Posted October 24, 2007 Share Posted October 24, 2007 Try something like this: <?php $lines = file('test_read.txt'); foreach ($lines as $line_num => $line) { list($type, $value) = explode(" = ", $line); if($type == checkbox) { echo "<input type=\"checkbox\" name=\"userbox\" value=\"$value\" /> $value"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74642-using-php-to-create-a-form-from-a-text-file/#findComment-377303 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.