Jump to content

Converting a CSV File


JSHINER

Recommended Posts

Here's where I'm at with this:

<?php

require('Database.php');

$db = new Database();
$handle = fopen('Mike.csv', 'r');

echo'
<table width="100%" border="0" cellspacing="0" cellpadding="0">
';

while ($row = fgetcsv($handle)) {


if($db->escape(trim($row[0]))=="Project") {

echo'
<tr>
    <td><b>Project</b></td>
    <td><b>Task</b></td>
    <td><b>Date</b></td>
    <td><b>Start</b></td>
    <td><b>End</b></td>
    <td><b>Duration</b></td>
</tr>';

}

else {

echo'
<tr>
    <td>', $db->escape(trim($row[0])), '</td>
    <td>', $db->escape(trim($row[1])), '</td>
    <td>', date("F j, Y", strtotime($db->escape(trim($row[2])))), '</td>
    <td>', date("g:i a", strtotime($db->escape(trim($row[3])))), '</td>
    <td>', date("g:i a", strtotime($db->escape(trim($row[4])))), '</td>
    <td>', $db->escape(trim($row[5])), '</td>
</tr>';

}

}

echo '</table>';

fclose($handle);
$db->close();

 

Now the only problem is I need to take the original CSV file and in Excel do Replace all for ( ; to , ) and ( " = (delete) )

 

I'm sure there must be a way to do this with preg_replace - but I can't get it to work. Any suggestions?

 

Link to comment
https://forums.phpfreaks.com/topic/95964-converting-a-csv-file/#findComment-492318
Share on other sites

Actually one last question. How can I get the contents of a directory? For example if /folder/ contained the following files:

- one.csv

- two.csv

- three.csv

 

How could I create a while statement to display:

 

one.csv - two.csv - three.csv

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/95964-converting-a-csv-file/#findComment-492332
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.