Making a CSV-formatted string : CSV File « File Directory « PHP






Making a CSV-formatted string

 
function make_csv_line($values) {
    foreach($values as $i => $value) {
        if ((strpos($value, ',')  !== false) ||
            (strpos($value, '"')  !== false) ||
            (strpos($value, ' ')  !== false) ||
            (strpos($value, "\t") !== false) ||
            (strpos($value, "\n") !== false) ||
            (strpos($value, "\r") !== false)) {
            $values[$i] = '"' . str_replace('"', '""', $value) . '"';
        }
    }
    return implode(',', $values) . "\n";
}
  
  








Related examples in the same category

1.Generating comma-separated data
2.Parsing CSV Strings
3.Read csv file
4.Reading CSV data from a file
5.Tell the web client to view the CSV file in a seprate program
6.fgetcsv.php
7.Printing comma-separated data
8.Putting comma-separated data into a string