Forum Moderators: coopster

Message Too Old, No Replies

Need to delete quotation marks from an already written-to file

I need to delete/remove double quotation marks from an already written file

         

fredfletcher

10:32 am on Jan 26, 2011 (gmt 0)

10+ Year Member



Hello,

I would like to know if someone can help me with this:

I have .csv file (semi-colon delimited) that has 5 columns with data being written to it from a user-submitted form and some of the fields have double quotation marks (") around them after the data file has been written to, the fields being $ip and $today

For example, the first 3 fields have no quotation marks, but the last two do:

Bob;Barker;bob@barker.com;"209.255.255.122";"26 Jan 2011 05:11 AM"

Is there a way to stop the quotation marks from being processed before the data gets written to the file?

Here is the code that is executed once the form has been submitted:

----------------------------------------
$list = array (

array($name, $lname, $email, $ip, $today)

);

$fp = fopen('/home/public_html/cgi-bin/data/file.txt', 'a+');

foreach ($list as $fields) {

fputcsv($fp, $fields, $delimiter = ';');

$fp= str_replace('"', "", $fp); < that didn't work for me

}

fclose($fp);

----------------------------------------

Thank you

vincevincevince

11:37 am on Jan 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is actually correct processing of the fields. If you don't want to use the standard CSV format, the easiest thing to do is write a loop and output it yourself, somethink like:

$line=implode(",",$fields); for each

fredfletcher

11:43 am on Jan 26, 2011 (gmt 0)

10+ Year Member



Hi Vince,

Thanks for the reply. Do I replace your suggestion with my

$fp= str_replace('"', "", $fp);

?