Location: PHPKode > scripts > xDIF > example.php
<?php

/*******************************************************
 * EXAMPLE NUMBER #1
 * Here's an example of how to create a spreadsheet from
 * an array and a list of headers.
 */
 require_once('xDif.class.php');
 //The two arrays and string below are input data
 $headers = array('Title','Genre','Author');
 $data    = array(
                  array('AdventureGuy','Adventure','John')
                  ,array('ActionMan','Action','Mike')
                  );
 $title = "My First Spreadsheet";
 //Create object and get converted data into string
 $xDif = new xDif;
 $difContent = $xDif->arrayToDif($headers,$data,$title);
 //You can then save it to a file to open up
 $xDif->toFile('Spreadsheet.dif',$difContent);
/*******************************************************/

/*******************************************************
 * EXAMPLE NUMBER #2
 * Here's an example of how to create a spreadsheet from
 * a MySQL database request
 * Instead of xDif->mysqlToDif you can use the following
 * xDif->mssqlToDif  for MsSQL
 * xDif->pgToDif     for PostgreSQL
 * xDif->ibaseToDif  for Ibase/Firebird
 */
 require_once('xDif.class.php');
 //Connect to database and do query
 $connection = mysql_connect('localhost','root','');
 mysql_select_db('exampledb');
 $queryResult = mysql_query("SELECT * FROM exampletable");
 $title = "My First Spreadsheet";
 //Create object and get converted data into string
 $xDif = new xDif;
 echo $difContent = $xDif->mysqlToDif($connection,$queryResult,$title);
 //You can then save it to a file to open up
 $xDif->toFile('MYSQLSpreadsheet.dif',$difContent);
/*******************************************************/
Return current item: xDIF