Solved

PHP CSV output and problem with date and escape chararacters

Posted on 2008-06-12
3
721 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

932 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

10 Experts available now in Live!

Get 1:1 Help Now