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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:07:55+00:00 2026-06-06T04:07:55+00:00

So, say you have a php post script that appends whatever you pass to

  • 0

So, say you have a php post script that appends whatever you pass to it to a text file as a new line

Let say the file is called file.txt and looks like this:

11:45 Am
12:49 PM
Went to Lunch
3:25 PM

I wanna know, how can I write a php script that treats information as pairs of 3.
so in a for loop it would display

line1 | line2 | line3
line4

Notice that there is nothing past line4, so it stopped.

  • 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-06T04:07:58+00:00Added an answer on June 6, 2026 at 4:07 am

    You can use (demo)

    $chunksOfThree = array_chunk(file('/path/to/file', FILE_IGNORE_NEW_LINES), 3);
    foreach ($chunksOfThree as $chunk) {
        echo implode(' | ', $chunk), PHP_EOL;
    }
    

    This will output the desired

    11:45 Am | 12:49 PM | Went to Lunch
    3:25 PM
    

    See the Manual entries for

    • file — Reads entire file into an array and
    • array_chunk — Split an array into chunks
    • implode — Join array elements with a string
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let say I have a post that can be found on page post.php?pid=60 but
I have a mail.php file that gets called by an ajax script. For completeness,
Say I have a PHP script that creates a cookie that expires 10 days
Let's say I have a PHP class called Color , it's constructor accepts various
Let's say i have an index.php that has html in it that looks like
Say I have a rewrite that needs to pass the url to a PHP
I have a script that posts data to a php script: xhr.open(POST,processData.php); And i
Let's say I have this javascript: <script language=javascript type=text/javascript> function addtext() { var newtext
Let's say I have an HTML page with a text field that ask the
I have a PHP script, say a.php , which is called from JS using

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.