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

  • SEARCH
  • Home
  • 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 542295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:25:53+00:00 2026-05-13T10:25:53+00:00

Let say i want to read a text file using php. Now my text

  • 0

Let say i want to read a text file using php.

Now my text file contain

User=Test
Age=18
Gender=F

User=Test2
Age=34
Gender=M

and following like that.

Now let say i want to use php to read the text file and find only value of User= and display it.

What is the easiest way to accomplish this?

Thank you.

  • 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-13T10:25:54+00:00Added an answer on May 13, 2026 at 10:25 am
    $filename = "users.txt";
    
    $user_file_array = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    
    //Now you have an array of each line of the file.
    
    foreach($user_file_array as $user_info) {
         if(strpos($user_info, "User=") !== false) {
               $users[] = str_replace("User=", "", $user_info);
          }
    }
    

    The above assumes that each bit of info is on a new line, that User= is case-sensitive, and that you are okay with looping through whole file. You will get an array returned of just the user names on the right-side of the User=.

    If you want that to be echoed out in a column, either change the bit where the $users array gets built, or add this to the end:

     echo implode("\n" $users);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning LINQ, and I want to read a text file (let's say
Let's say I have a text file that is 100 lines long. I want
I'm reading in a text file using BinaryReader, then doing what I want with
Let's say I want to run a .NET application on a machine where the
Let's say I want a web page that contains a Flash applet and I'd
Let's say I want a way to display just the the center 50x50px of
Let's say I want to write a regular expression to change all <abc> ,
Let's say I want to represent \q (or any other particular backslash-escaped character). That
Let's say you want to start contributing to an open source project with thousands
Let's say I want to draw a simple quad like this: glBegin(GL_QUADS); glVertex2f(-1.0,-1.0); glVertex2f(1.0,-1.0);

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.