- parseCSV is an easy to use PHP class to read and write CSV data properly.
- Download parseCSV 0.4.3 beta.

Features

• Supports enclosed values, enclosed commas, double quotes and new lines.
• Automatic delimiter character detection.
• Sort data by specific fields/columns.
• Easy data manipulation.
• Basic SQL-like conditions, offset and limit options for filtering data.
• Store CSV data into an array, convert array to CSV data.
• Error detection for incorrectly formatted input. It attempts to be intelligent, but can not be trusted 100% due to the structure of CSV, and how different programs like Excel for example outputs CSV data.
• Support for character encoding conversion using PHP's iconv function (requires PHP 5).

Examples
- These examples use this CSV, saved in "books.csv":
rating,title,author,type,asin,tags,review
0,The Third Secret,Steve Berry,Book,0340899263,,need to find time to read this book
3,The Last Templar,Raymond Khoury,Book,0752880705,,
4,The Da Vinci Code (Hardcover),Dan Brown,"     Book     ",0385504209,book movie danbrown bestseller davinci,

1. Read a CSV file (with auto-detect delimiter character) and store data into an array:
<?php
// include parseCSV class
include('parsecsv/parsecsv.class.php');

// create new parseCSV object
$csv = new parseCSV();

// Parse 'books.csv' using automatic delimiter detection
$csv->auto('books.csv');

// if you know the delimiter, set the delimiter character (if not the default comma)
// $csv->delimiter = "\t";         // tab delimited

$csvdata = $csv->data;               // gets csv data into an array

// output result
echo '<pre>';
print_r($csvdata);
echo '</pre>';
?>

Result:
Array
(
  [0] => Array
    (
      [rating] => 0
      [title] => The Third Secret
      [author] => Steve Berry
      [type] => Book
      [asin] => 0340899263
      [tags] => 
      [review] => need to find time to read this book
    )
  [1] => Array
    (
      [rating] => 3
      [title] => The Last Templar
      [author] => Raymond Khoury
      [type] => Book
      [asin] => 0752880705
      [tags] => 
      [review] => 
    )
  [2] => Array
    (
      [rating] => 4
      [title] => The Da Vinci Code (Hardcover)
      [author] => Dan Brown
      [type] =>    Book   
      [asin] => 0385504209
      [tags] => book movie danbrown bestseller davinci
      [review] => 
    )
)

2. Read the CSV file, sorting data by "title".
<?php
// include parseCSV class.
include('parsecsv/parsecsv.class.php');

// create new parseCSV object
$csv = new parseCSV();

$csv->sort_by = 'title';

// Parse 'books.csv' using automatic delimiter detection...
$csv->auto('books.csv');

$csvdata = $csv->data;               // get csv data into an array

// output result
echo '<pre>';
print_r($csvdata);
echo '</pre>';
?>

Result:
Array
(
  [The Da Vinci Code (Hardcover)] => Array
    (
      [rating] => 4
      [title] => The Da Vinci Code (Hardcover)
      [author] => Dan Brown
      [type] =>    Book   
      [asin] => 0385504209
      [tags] => book movie danbrown bestseller davinci
      [review] => 
    )
  [The Last Templar] => Array
    (
      [rating] => 3
      [title] => The Last Templar
      [author] => Raymond Khoury
      [type] => Book
      [asin] => 0752880705
      [tags] => 
      [review] => 
    )
  [The Third Secret] => Array
    (
      [rating] => 0
      [title] => The Third Secret
      [author] => Steve Berry
      [type] => Book
      [asin] => 0340899263
      [tags] => 
      [review] => need to find time to read this book
    )
)

3. Convert 2D array to CSV, and send headers to browser to treat output as a file and download it.
<?php
// include parseCSV class.
include('parsecsv/parsecsv.class.php');

$csvHeader = array('category', 'link');              // csv header

// 2 dimensional array with data for csv (according to header)
$csvData = array(
  array('tutorials', 'http://coursesweb.net/php-mysql/tutorials_t'),
  array('scripts', 'http://coursesweb.net/php-mysql/scripts_s2'),
  array('resources', 'http://coursesweb.net/php-mysql/download_l2')
 );

// create new parseCSV object
$csv = new parseCSV();

// convert 2D array to csv data and output as a file to download it
// (filename, csv-data, csv-header, delimiter)
$csv->output('coursesweb.csv', $csvData, $csvHeader, ',');
?>

Result this CSV:
category,link
tutorials,http://coursesweb.net/php-mysql/tutorials_t
scripts,http://coursesweb.net/php-mysql/scripts_s2
resources,http://coursesweb.net/php-mysql/download_l2

- In the archive with parseCSV class you'll find other examples too.
parseCSV Web Site.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which attribute specifies the URL address where to send the form-data?
method action name
<form action="script.php" method="post"> ... </form>
Which CSS property can be used to break lines in the middle of words?
word-wrap line-height font-size
#id {
  width: 100px;
  word-wrap: break-word;
}
Which function sorts the elements of an array into alphabetical order, based on the string values?
pop() sort() shift()
var tutorials = ["php", "html", "css", "flash"];
tutorials.sort();
alert(tutorials[0]);          // css
Indicate the function that returns the value of the last element into an array.
current() next() end()
$code = array(10=>"Perl", 20=>"PHP", 21=>"Python", 30=>"JavaScript");
$last = end($code);
echo $last;      // JavaScript
parseCSV

Last accessed pages

  1. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (18225)
  2. PHP PDO - Introduction and Connecting to Databases (3731)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (21455)
  4. PHP getElementById and getElementsByTagName (6951)
  5. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (24788)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (24788)
  2. PHP-MySQL free course, online tutorials PHP MySQL code (21455)
  3. Get Attribute (ID, Class, Name, Title, Src) with jQuery (20841)
  4. Read Excel file data in PHP - PhpExcelReader (18397)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (18225)