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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:03:43+00:00 2026-05-16T22:03:43+00:00

Using php, I’m trying to create a script which will search within a text

  • 0

Using php, I’m trying to create a script which will search within a text file and grab that entire line and echo it.

I have a text file (.txt) titled “numorder.txt” and within that text file, there are several lines of data, with new lines coming in every 5 minutes (using cron job). The data looks similar to:

2 aullah1
7 name
12 username

How would I go about creating a php script which will search for the data “aullah1” and then grab the entire line and echo it? (Once echoed, it should display “2 aullah1” (without quotations).

If I didn’t explain anything clearly and/or you’d like me to explain in more detail, please comment.

  • 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-16T22:03:44+00:00Added an answer on May 16, 2026 at 10:03 pm

    And a PHP example, multiple matching lines will be displayed:

    <?php
    $file = 'somefile.txt';
    $searchfor = 'name';
    
    // the following line prevents the browser from parsing this as HTML.
    header('Content-Type: text/plain');
    
    // get the file contents, assuming the file to be readable (and exist)
    $contents = file_get_contents($file);
    
    // escape special characters in the query
    $pattern = preg_quote($searchfor, '/');
    
    // finalise the regular expression, matching the whole line
    $pattern = "/^.*$pattern.*\$/m";
    
    // search, and store all matching occurences in $matches
    if (preg_match_all($pattern, $contents, $matches))
    {
       echo "Found matches:\n";
       echo implode("\n", $matches[0]);
    }
    else
    {
       echo "No matches found";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do this interactively with: M-s h r regexp… May 17, 2026 at 2:27 am
  • Editorial Team
    Editorial Team added an answer DataAnnotations works by decorating properties on a type with attributes,… May 17, 2026 at 2:27 am
  • Editorial Team
    Editorial Team added an answer You're messing up your data to deal with a matter… May 17, 2026 at 2:27 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Using PHP, I'm trying to give each specific text its own variable. I believe
Using PHP and MySQL, I have a forum system I'm trying to build. What
Using PHP, and MySql, I am trying to implement this rather snazzy in-place editor
Using PHP, is there a function/method/way to check if a variable contains something that
Using PHP's system function, how can you pass arguments to a batch file? It
Using PHP, what's the fastest way to convert a string like this: 123 to
Using PHP, Perl, or Python (preferably PHP), I need a way to query an
Using PHP, given a URL, how can I determine whether it is an image?
Using PHP and MySQL, I want to query a table of postings my users
Using php's DOMDocument->LoadHTMLFile('test.html'); keeps on returning an error to me, reporting for an error

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.