PHP : Generate Excel file

<?php

$header = array(‘First Name’,’Last Name’,’About you Description’);

// Create a array having xls information to print. It could be get from database.
$xls_data_to_print = array(
‘0’=>array(
‘first_name’=> ‘John’,
‘last_name’=> ‘Rawal’,
‘about_info’=> ‘He is a great player.’,
),

‘1’=>array(
‘first_name’=> ‘John1’,
‘last_name’=> ‘Rawal1’,
‘about_info’=> ‘He is a great player1.’,
),

);
$xls_content_row = ”;
foreach($xls_data_to_print as $xls_ky => $xls_val){
// Write a code here to generate XLS file with required details.
// Use $xls_val->title OR $xls_val[‘title’] depending array type.
$rows = array();
$rows[]= $xls_val[‘first_name’];
$rows[]= $xls_val[‘last_name’];
$rows[]= $xls_val[‘about_info’];

$xls_content_row .= implode(“\t”, array_values($rows)) . “\r\n”;
}
$xls_content_header = implode(“\t”, array_values($header));
$xls_content = $xls_content_header.”\n”.$xls_content_row;
$filename = ‘Xls_data_list_’.date(“d_m_Y”);
header(“Content-type: text/plain; charset=UTF-8”);
header(“Content-Disposition: attachment; filename=$filename”);
header(“Content-Type: application/vnd.ms-excel”);
header(“Pragma: no-cache”);
header(“Expires: 0”);
print $xls_content;
die();

Phalcon : Email Send Code

Step 1: Install Phalcon, Phalcon Tools

Installing Phalcon is easy if you just follow the instructions on their website. Don’t forget to install the Phalcon tools as well!

If you’re using Vagrant, you can also install the whole set into your box by following this tutorial.

Step 2: Initial setup of our application

We’ve successfully set up the development environment. Now we proceed to create the skeleton of our application. Open terminal (in Linux & Mac) or command prompt (cmd in Windows) and type following in the folder where you keep your web projects:

    phalcon project sendmail

This will produce the following file and folder structure:
Continue reading