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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:24:02+00:00 2026-05-24T12:24:02+00:00

I need to print out csv file into html or put a numeric data

  • 0

I need to print out csv file into html or put a numeric data into database:
But I need to start a loop at specific position and break it at another specific position (regex).
So I need to reprint only rows with numerical data and all columns from them.
Following is pseudo-code – not working properly:

<?php
$row = 1;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle, 1000, ","))
{
   if (preg_match('/[Morning]/', $data[0]) === 1 // start at this rwo plus two lines down )
    {
    $num = count($data);
    $row++;
      for ($c=0; $c < $num; $c++)
      {
            for ($c=0; $c < $num; $c++)
            {  
              echo $data[$c] . " ";
            }   
      if (preg_match('/[Total Cash:]/', $data[0]) === 1)
        { break; row -1 }            
      }
       echo "<br>";  
   }
}
fclose($handle); ?>

So csv goes like this:

/--some lines--/

Date: 3/3/11, Morning, --blank line--- Customer No,Time,CheckNo,Total, 1234,12-45,01,20.00, 1236,1-00,03,30.00, 1240,2-00,06,30.00, --more numerical rows of data at variable length that I need to loop over-- 1500,4-00,07,22.00, ----,----,---,----, Total Cash, , , ,120.00,

/--some other lines--and it goes/

Lunch Time, ---similar like Morning above ---

Any info how to properly addrres this issue is appreciated, I can now do so many loops and regex but with this I need some more time and help. Thanks.

  • 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-24T12:24:03+00:00Added an answer on May 24, 2026 at 12:24 pm
    $lines = file('test.csv'); //read file into an array, one entry per line
    
    $active = false; //keep track of what rows to parse
    
    //loop one line at a time
    for ($i = 0; $i < count($lines); $i++) {
      $line = $lines[$i];
    
      if (strpos($line, 'Morning') !== false) { //start parsing on the next row
        $active = true;
        $i += 2; //skip the blank line and header
        continue;
      }
      if (strpos($line, '----,') !== false) { //stop parsing rows
        $active = false;
      }
    
      if ($active) { //if parsing enabled, split the line on commas and do something with the values
        $values = str_getcsv(trim($line));
        foreach ($values as $value) {
          echo $value . " "; //these are the numbers
        }
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to print out data into a pre-printed A6 form (1/4 the size
I need to print out the contents of an xml file into some txt
I have csv file having some address data mostly in Finnish language. I need
I have a csv file I need to cleanup. It contains 13 fields, but
i need to print out numbers 1-100 in a random order. the print statement
The following code, prints out Derived Base Base But I need every Derived object
I need to print last 20 characters of string, but only whole words. Delimiter
I have CSV file with sample data in this form : 220 30 255
I need to print out a 3 by 3 matrix in C. I could
I have this HashMap that I need to print out in ascending order according

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.