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 3321168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:01:50+00:00 2026-05-17T23:01:50+00:00

if get an input from the user and i wanted to search the file

  • 0

if get an input from the user and i wanted to search the file for any results, and display the results:

$searchValue = $_POST['search'];

$handle = @fopen("home.txt","r");
# read line by line
while (($buffer = fgets($handle, 4096)) !== false && // the condtion for the $searchValue) {
    echo '<tr>';
        $array = explode(',', $buffer);
    foreach($array as $val){
         echo '<td>'.$val.'</td>';      
        } 
    echo '</tr>';       
}

i dnt get what i have to do, i just want to display the rows in the text file with relevent $searchvalues

  • 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-05-17T23:01:50+00:00Added an answer on May 17, 2026 at 11:01 pm

    I would even recommend using the file command:

    array file  ( string $filename  [, int $flags = 0  [, resource $context  ]] )
    

    Reads a file in with each line as an element in the array. From there, you would iterate each line (you mentioned returning the rows in the file that matched which is why I recommend file(…) ):

    if (($fileLines = file('home.txt')) !== false)
    {
      foreach ($fileLines as $line)
      {
        if (strpos($line, $searchVal) !== false)
        { // match found
          echo '<tr><td>'.str_replace(',','</td><td>',trim($line)).'</td></tr>';
        }
      }
    }
    

    No use exploding the array just to rejoin it again. You could also explode it then implode() it with the </td><td> as well.

    Also, it seems like your file has rows of CSVs. If that’s the case, you may want to iterate each row, then explode(…) the items and perform an in_array(…) (or iterate through with strpos for partial matches again) on the exploded variable. e.g.:

    $values = explode(',',$line);
    // array search (while entries)
    if (in_array($searchVal,$values)) { ... }
    // array search with partial matches
    foreach ($values as $val) {
      if (strpos($val,$searchVal) !== false) { ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function where I get input from a user def get_single_argument(argument,name) begin
This is my first post here and I wanted to get some input from
Is it possible to get input from a user using PHP CLI, then dump
I want to get input from user . The inputs are text type such
I'm using inputText to get input from a user <h:inputText id=firstName value=#{beanManager.currentUser.firstName } required=true
How can I build an android app which basically get the inputs from user
Is there anyway to use pygame to get input from the console, rather than
I am trying to get text input from the keyboard in Java 6. I
I'm maintaining a script that can get its input from various sources, and works
I'm working on a small project in VB.Net where I get a input from

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.