Solved

PHP CSV output and problem with date and escape chararacters

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

705 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