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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:29:26+00:00 2026-06-07T13:29:26+00:00

I am new to php, I need to read a text file’s 5th line

  • 0

I am new to php, I need to read a text file’s 5th line and see if it contains a particular string
what would be the most efficient way to do it ?
I understand I can ready all lines using this method, should I put a counter here and break the loop if it is 5 ? or is there a better way to it ..

 $file = fopen($fileName,'r');
    while(!feof($file)) 
    { 
        $name = fgets($file);            
    }

    fclose($file);

EDIT

I have updated my code to this, but strpos always fails to find the string even if it is present..
I have verified the 5th line looks like this
PACKAGE_NAME: com.boom.appfree

//read entire file into an array 
$lines = file($target_path);

//check line 5 if it contains free
$pos = strpos($line[4], 'free');

if ($pos === false) 
{
  $subject = "Paid Log uploaded";
} else 
{
   $subject = "Log uploaded";
}

Any advise please..

  • 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-07T13:29:29+00:00Added an answer on June 7, 2026 at 1:29 pm

    $lines =file("filename.txt");

    Then you can get the fifth line: $lines[4] and search it for the word you are looking for with strpos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to php and I need a hand. I have width by height
I am new to PHP. I need to GET a xml stored locally using
I'm new to PHP so I don't know whether this is possible. I need
Im new to JSON and php. I need to grab the lat and lng
I'm very new in programming. I'm writing a PHP application that need to execute
I've got a problem where I'm trying to read a text file like this:
I'm creating a website and new to php and mysql. I just read as
For my new heavy database read application ,i need to use GWT and mysql.
I have a csv file I need to cleanup. It contains 13 fields, but
I am new to MySql/PHP. Each row from Database1.table1 has to be read and

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.