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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:10:44+00:00 2026-06-18T02:10:44+00:00

Need some help with parsing a text file into PHP. The file is generated

  • 0

Need some help with parsing a text file into PHP. The file is generated by a PHP script, so I don’t have control over the content formatting. The text file looks like this:

7/4/2013-7/4/2013
Best Legs in a Kilt
To start the summer
off with a bang, the Playhouse has teamed up with the folks at The
Festival.
kilt.jpg
1,1,0,
–

7/8/2013-7/23/2013
Hot Legs
Yes, folks, it’s all platform
shoes, leisure suits, and crazy hair-do’s.
hotstuff.jpg
1,1,0,
–

The code that I have thus far is:

$content = file_get_contents('DC_PictureCalendar/admin/database/cal2data.txt');

list($date, $showname, $summary, $image, $notneeded, $notneeded2) = explode("\n", $content);

echo 'Show Name' . $showname . '<br/>';

This only gets me the first show title, I need to grab all of them. I’m sure a For loop would do it, but not sure how to do it based on the contents of the file. All I need is the 2nd line (show title) and the 4th line (image). Any help? Thanks in advance.

  • 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-18T02:10:45+00:00Added an answer on June 18, 2026 at 2:10 am

    If you are reading the entire file into an array anyway, then just use file() which will read each line into an array.

    $content = file('DC_PictureCalendar/admin/database/cal2data.txt', FILE_IGNORE_NEW_LINES);
    

    You can then filter all the lines you don’t want like this

    $content = array_diff($content, array('1,1,0', '-'));
    

    You can then break into chunks of 4 lines each (i.e. one item per entry)

    $content_chunked = array_chunk($content, 4);
    

    This would give you an array like

    Array(
        0 => Array(
            0 => '7/4/2013-7/4/2013',
            1 => 'Best Legs in a Kilt',
            2 => 'To start the summer off with a bang, the Playhouse has teamed up with the folks at The Festival.',
            3 => 'kilt.jpg'
        ),
        1 => Array(
            0 => '7/8/2013-7/23/2013',
            1 => 'Hot Legs',
            2 => 'Yes, folks, it's all platform shoes, leisure suits, and crazy hair-do's.',
            3 => 'hotstuff.jpg'
        ) ... etc.
    )
    

    I would then map this array into a useful array of objects with property names that are meaningful to you:

    $items = array_map(function($array)) {
        $item = new StdClass;
        $item->date = $array[0];
        $item->showname = $array[1];
        $item->summary = $array[2];
        $item->image = $array[3];
        return $item;
    }, $content_chunked);
    

    That would leave you with an array of objects like:

    Array(
        0 => stdClass(
            'date' => '7/4/2013-7/4/2013',
            'showname' => 'Best Legs in a Kilt',
            'summary'  => 'To start the summer off with a bang, the Playhouse has teamed up with the folks at The Festival.',
            'image' => 'kilt.jpg'
        ),
        1 => stdClass(
            'date' => '7/8/2013-7/23/2013',
            'showname' => 'Hot Legs',
            'summary' => 'Yes, folks, it's all platform shoes, leisure suits, and crazy hair-do's.',
            'image' => 'hotstuff.jpg'
        ) ... etc.
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with parsing a string in Linux. I have a string:
I need some help on parsing the Command Line for a lua file. I
I need some help with parsing a line of text. The line of text
I need help parsing out some text from a page with lxml. I tried
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help with a query.. I have three tables. Source id name 1
Need some help with DataFormatString in GridView. I have a Double value that needs

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.