Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8199129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:06:32+00:00 2026-06-07T06:06:32+00:00

I have a php file that reads in information from a txt file and

  • 0

I have a php file that reads in information from a txt file and prints it on the screen into lines such as

1st line [ x ]
2nd line[ x ]
etc etc etc

i am trying to add checkboxes next to all the lines of information, i managed to do a for loop that creates checkboxes depening on how many lines are read.

Now the final thing which i am stuck on is that i want the user to be able to click on any checkboxes and then click the submit button which should print out the chosen information on a new php file.

If the user ticked 1st line and submitted then it should display the text string “1st line” on the opening php file

I done some research and managed to use isset method to find out if it was checked, that worked but im still unsure how to read the information that was checked onto a new php file any help would be appreciated thank you

$filename = "file.txt";

$filepointer = fopen($filename, "r"); //open for read

$myarray = file ($filename);

// get number of elements in array with count
for ($counts = 0; $counts < count($myarray); $counts++)

{ //one line at a time
$aline = $myarray[$counts];

//$par = array();
$par = getvalue($aline);

if ($par[1] <= 200) 
{ 

print "<input type=checkbox name='test'/>"." ".$par[0]." "; 
print $par[1]." ";
print $par[2]." ";
print $par[3]." ";

}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:06:33+00:00Added an answer on June 7, 2026 at 6:06 am

    I think you are probably wanting to create an array which identifies which lines were checked? Well, you’ll want to use an array to name your checkbox inputs. You can do this with a very similar syntax to PHP, by appending [] to the input name. For this specific case, you’ll also want to explicitly index the array keys, which you can do like [index]. It will be easier to demonstrate this in code:

    file1.php (FIXED):

    <?php
    
    $filename = "file.txt";
    
    // file() does not need a file pointer
    //$filepointer = fopen($filename, "r"); //open for read
    
    $myarray = file($filename);
    
    print "<form action='file2.php' method='post'>\n";
    
    // get number of elements in array with count
    $count = 0; // Foreach with counter is probably best here
    foreach ($myarray as $line) {
    
      $count++; // increment the counter
    
      $par = getvalue($line);
    
      if ($par[1] <= 200) {
        // Note the [] after the input name
        print "<input type='checkbox' name='test[$count]' /> ";
        print $par[0]." "; 
        print $par[1]." ";
        print $par[2]." ";
        print $par[3]."<br />\n";
      }
    
    }
    
    print "</form>";
    

    file2.php:

    <?php
    
      foreach ($_POST['test'] as $lineno) {
        print "Line $lineno was checked<br />\n";
      }
    

    EDIT

    Say you wanted file2.php to display the lines from the file that were checked:

    <?php
    
      $filename = "file.txt";
    
      $myarray = file($filename);
    
      foreach ($_POST['test'] as $lineno) {
        // We need to subtract 1 because arrays are indexed from 0 in PHP
        print $myarray[$lineno - 1];
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file that dynamically read information from various sources, like search.php?q=keyword&category=cat-number
I have a simple script of code that reads a PHP file and when
I have a PHP file that serves up a JSON array populated from a
I want to sent some information through a from, executing a php file that
I have a file that pulls some information from the database and creates some
I have a PHP file which writes some information into a configuration file which
I have a 1.3GB text file that I need to extract some information from
I have a gzipped text file that I'm trying to read within PHP (using
I have a PHP file that contains a large array (about 90KB). I'm considering
I have a PHP file that contains a lot of if and else statements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.