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

  • Home
  • SEARCH
  • 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 6643133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:00:50+00:00 2026-05-26T00:00:50+00:00

So I was able to parse the txt file into a csv file $data

  • 0

So I was able to parse the txt file into a csv file

$data = array();
while ($line= fgets ($fh)) {
$stack = array($LAUS,$FIPS,$CountyName,$Date,$_CLF,$_EMP,$_UNEMP,$RATE);
        array_push($data, $stack);
}
$file = fopen('file.csv','w');

foreach ($data as $fields) {
fputcsv($file, $fields,',','"');
 }

fclose($file);

My question is, what is the best way to create multiple csv files that are seperated by Month (also the year, like Jan01.csv, Jan02.csv).

  • 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-26T00:00:51+00:00Added an answer on May 26, 2026 at 12:00 am

    I’m taking a bit of a guess at the formatting of your date

    while ($line = fgets ($fh)) {
        // Not sure where you're getting these values, but I'm assuming it's correct
        $stack = array($LAUS,$FIPS,$CountyName,$Date,$_CLF,$_EMP,$_UNEMP,$RATE);
    
        // Assuming $Date looks like this '2011-10-04 15:00:00'
        $filename = date('My', strtotime($Date)) . '.csv';
        $file = fopen($filename,'a+');
        fputcsv($file, $stack,',','"');
        fclose($file);
    }
    

    This will be a little slow since you’re opening and closing files constantly, but since I don’t know the size of your original data set I don’t want to use up all the memory caching the result before I write it.

    Be aware that running this multiple times will end up with duplicate data being inserted into your CSV files. You may want to add some code to remove/clear out any currently existing CSV files before you run this bit of code.

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

Sidebar

Related Questions

I am able to parse a .DRL file into the XmlDumper and get the
I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into
I am new to iphone development.I am able to parse a Xml file at
I need to be able to parse this sort of data in PHP: Acct:
I have become able to parse the xml url using TBXML parser. parsed data
I need to be able to parse an HTML template file (with the intention
Data File: ( Data.txt ) lines represent width height 5 6 9 7 2
i'm able to parse in and display data for all pieces of my code
i am able to parse the XML file. but i am facing strange error.
I want to be able to parse this date-time format 2011-12-02T16:18:12.479-05:00 into an mm/dd/yy

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.