csv output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
faza
Forum Newbie
Posts: 9
Joined: Tue Jun 22, 2010 4:28 pm

csv output

Post by faza »

im having problems exporting to csv

$csv_output .= $result['domain'] . "\n" . $result['whois'] . "\n" . $result['dig'] . "\t" . ;

Theres something wrong with this syntax ?

Please help

I need the csv file to each of the results to be in a seperate column and then for it to break to the next line
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: csv output

Post by AbraCadaver »

What does the C in CSV stand for? I don't see any of those. You also have an extraneous . near the end of your string.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: csv output

Post by Jade »

You know this is the second post in the past what, 3 days, where someone has left the C outta the CSV files. Interesting....
faza
Forum Newbie
Posts: 9
Joined: Tue Jun 22, 2010 4:28 pm

Re: csv output

Post by faza »

this is now working had help from a another programmer
$csv_output = "Domain\tWhois\tdig\tavailability\t\n";
$filename = "multi_whois.xls";
foreach ($results as $result){
$whois = str_replace('"', "'", $result['whois']);
$return = str_replace("1", "UNAVAILABLE", $result['availability']).
// $return = $availability

$csv_output .= $result['domain'] . "\t" . '"'. $whois .'"'. "\t" . '"' . $result['dig'] . '"' . "\t" . $return . '"' ."\n";
}

WAS told not to use commas as the data from the whois statment can return commas and then this will break when its exported to csv!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: csv output

Post by AbraCadaver »

Then that is tab delimited not comma delimited. If you quote text in a CSV file then the commas are not a problem:
[text]"column 1 with a , in it","column 2, with 2 , s in it","etc, etc, etc..."[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply