Solved

PHP CSV output and problem with date and escape chararacters

Posted on 2008-06-12
3
719 Views
Last Modified: 2008-06-17
I'm having a problem with escaping commas inside a date field when writing to a CSV file,

the date is in the format of "June 12, 2008, 1:29 pm"
the commas wreck the formatting, how would i change it so this doesn't happen?

Cheers
$list = array (

    'Name,County,Date completed,Coach name, Level, How long known,Psych name,MTP overall score,Statement 1,statement 2,statement 3,Fight average,ID average,CMC average,Res Average,Fight statement 1,Fight Statemt 2,Fight Statemt 3,ID statemt 1,ID statement 2,ID statement 3,CMC statemt 1,CMC statemt 2,CMC Statemt 3,Res Statemt 1,Res Statemt 2,Res Statemt 3',

    ''.$name.','.$date.','.$temp.','.$coach.','.$namelevel.','.$coachingtime.','.$psychologist.','.$temp.','.$temp.','.$temp.','.$temp.','.$a4.','.$b4.','.$c4.','.$d4.','.$a1.','.$a2.','.$a3.','.$b1.','.$b2.','.$b3.','.$c1.','.$c2.','.$c3.','.$d1.','.$d2.','.$d3.'');
 
 

$number = rand(0,101101);

$username = $_SESSION['Username'];

$_SESSION['csv']="temp/mycsv".$number.$username.".jpg";

$fp = fopen('temp/mycsv'.$number.$username.'.csv', 'w');
 

foreach ($list as $line) {

    fputcsv($fp, split(',', $line));

}
 

fclose($fp);

Open in new window

0
Comment
Question by:FurnakTye
  • 2
3 Comments
 
LVL 9

Expert Comment

by:zemond
ID: 21769328
you will need to replace the commas with another delimiter, perhaps - to produce June 12-2008-1:29 pm
0
 
LVL 9

Accepted Solution

by:
zemond earned 125 total points
ID: 21769369
$date = str_replace(',', '-', $date);
0
 
LVL 13

Expert Comment

by:marchent
ID: 21769527
You can use preg_replace()  function too, to replace comma,
$date = preg_replace("/,/", '-', $date);
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now