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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:18:05+00:00 2026-05-13T19:18:05+00:00

I have three eintries in a textfile.txt: 20100220 Hello Here is Text \n blah

  • 0

I have three eintries in a textfile.txt:

20100220
Hello
Here is Text \n blah \t even | and & and so on...

I want to read each entrie (line) as a new string in php. I thought of using fopen and fgets. But: Since I’m using special characters like \n in the last line, fgets() would not work because it will terminate the string at \n, right? In a result the last line would be just ‘Here is Text ‘.

How can I read/explode the three lines the right way, so the \n in the last line would be interpreted as a normal string?
Thanks!

p.s.
By having three lines in my textfile.txt I indirect chose \n as a delimiter, but I could also use another delimiter. what is just the best way to read the content?

  • 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-13T19:18:05+00:00Added an answer on May 13, 2026 at 7:18 pm

    You have two options:

    1.- Use file() to get an array with an element for each line (separated by ‘\n’)

    $lines_of_file = file("myfile.txt");
    //Now $lines_of_file have an array item per each line
    

    2.- Use file_get_contents() to get a single string you can then split by any separator you want

    $file_content = file_get_contents("myfile.txt");
    $file_content_separated_by_spaces = explode(" ", $file_content);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have database like which have three coloums( id(integer) , startdate(text), enddate(text),). I want
I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g., nested_list
Have three divs in a container that I want to float over a large
i have three lists with the same number of elements in each other, i
I have few Gigabytes text file in format: {user_ip:x.x.x.x, action_type:xxx, action_data:{some_key:some_value...},...} each entry is
I have three tables, which are each 1:n. An entry in table1 has n
I have three tables and I want to update all values for a particular
I have three unordered lists each containing a subset of a group of items
I have a 384MB text file with 50 million lines. Each line contains 2
I have three queries and I want result rows consisting of entries of these

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.