Jump to content

Problem Writing to CSV


onlyican

Recommended Posts

Hey guys

I am building a Custom error Logger

So I can do better quiries on it, I am adding it to a csv

but
Some errors are MySQL Errors, which have commas

and as CSV should do, it puts a coma as a new cell

I tried replacing the commas with \,
but it just adds a slash
then puts it in a new cell

anyone know a way round this
Link to comment
https://forums.phpfreaks.com/topic/30124-problem-writing-to-csv/
Share on other sites

Hi this might be a simple solution but you could write a quick function to iterate over the text changing all commas to another symbol not found in a sentence such as "~" . write the csv file then, when you pull the csv file run a reverse function on it, or it could be one function:-
[code]
<?php

$ans = preg_replace(',', '~', $text);

?>[/code]

over simplified solution but it just might work
How are you using the CSV file? Via PHP? If so, take a look at the [url=http://www.php.net/fgetcsv]fgetcsv()[/url] function. This function has an option which lets you tell it a quote character so commas between the quotes are ignored.

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.