- 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 tag can be used to create input text field in web page?
<form> <input> <div>
<input type="text" name="a_name" value="val" />
Which CSS property displays the text in a small-caps font?
display font-variant font-style
h3 {
  font-variant: small-caps;
}
What instruction displays a notice box with a message inside it, in JavaScript?
for() Date() alert()
var msg = "Visit CoursesWeb.net";
alert(msg);
Indicate the PHP code used to get the users IP.
$_SERVER["HTTP_USER_AGENT"] $_SERVER["REMOTE_ADDR"] $_GET[]
$ip = $_SERVER["REMOTE_ADDR"];
echo $ip;
parseCSV

Last accessed pages

  1. jQuery ajax() method (1194)
  2. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (3210)
  3. HTML object and param (885)
  4. Upload Script for Gallery of Images and Audio files (625)
  5. Add Pause in JavaScript script (557)

Top accessed pages

  1. PHP-MySQL free course, online tutorials PHP MySQL code (3366)
  2. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (3247)
  3. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (3210)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (2959)
  5. PHP Chat Script (2659)