?
Solved

PHP CSV output and problem with date and escape chararacters

Posted on 2008-06-12
3
Medium Priority
?
728 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 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…
Suggested Courses

752 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