Skip to content

Instantly share code, notes, and snippets.

View vrushank-snippets's full-sized avatar

Vrushank vrushank-snippets

View GitHub Profile
@vrushank-snippets
vrushank-snippets / css template
Created May 4, 2012 11:13
CSS : Start Template
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
background: transparent;
@vrushank-snippets
vrushank-snippets / Print Array Helper
Created June 27, 2012 09:52
CODEIGNITER : Print Array Helper
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('mpr'))
{
function mpr($d, $echo = TRUE)
{
if($echo)
{
echo '<pre>'.print_r($d, true).'</pre>';
}
@vrushank-snippets
vrushank-snippets / PHP : Date Difference
Created December 12, 2012 07:39
PHP : Date Difference
<?php
$date1 = '2009-12-20 20:12:10';
$date2 = '2009-12-24 12:12:10';
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$seconds_diff = $ts2 - $ts1;
echo floor($seconds_diff/3600/24);
@vrushank-snippets
vrushank-snippets / Yii : Auto Complete In Grid
Created December 12, 2012 07:43
Yii : Auto Complete In Grid
<?php
array(
'name'=>'name',
'type'=>'raw',
'value'=>'$data->name',
'filter'=>$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>$model,
'attribute'=>'name',
'source'=>$this->createUrl('user/usersAutoComplete'),
'options'=>array(
@vrushank-snippets
vrushank-snippets / PHP : Array To CSV
Created December 12, 2012 11:26
PHP : Array To CSV
/**
* Generating CSV formatted string from an array.
*/
function array_to_csv($array, $header_row = true, $col_sep = ",", $row_sep = "\n", $qut = '"')
{
if (!is_array($array) or !is_array($array[0])) return false;
//Header row.
if ($header_row)
{
@vrushank-snippets
vrushank-snippets / PHP : Array To CSV - Download CSV File
Created December 13, 2012 06:21
PHP : Array To CSV - Download CSV File
$fileName = 'Billing-Summary.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$fh = @fopen( 'php://output', 'w' );
@vrushank-snippets
vrushank-snippets / PHP : Json OR Array To XML Conversion
Created December 13, 2012 10:50
PHP : Json OR Array To XML Conversion
<?php
function arrayToXml($array, $rootElement = null, $xml = null) {
$_xml = $xml;
if ($_xml === null) {
$_xml = new SimpleXMLElement($rootElement !== null ? $rootElement : '<root><root/>');
}
foreach ($array as $k => $v) {
@vrushank-snippets
vrushank-snippets / PHP : XML TO JSON
Created December 13, 2012 10:53
PHP : XML TO JSON
$fileContents = file_get_contents('http://webdevelopergeeks.com/demo/sms.xml');
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
@vrushank-snippets
vrushank-snippets / Yii : Flash Messages
Created December 24, 2012 08:54
Yii : Flash Messages
$flashMessages = Yii::app()->user->getFlashes();
if ($flashMessages) {
foreach($flashMessages as $key => $message) {
echo '$message';
}
}
@vrushank-snippets
vrushank-snippets / Yii : Date Picker
Created December 24, 2012 08:57
Yii : Date Picker
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'from_date',
'options'=>array(
'showAnim'=>'fold', // 'show' (the default), 'slideDown', 'fadeIn', 'fold'
'dateFormat'=>'dd-mm-yy',
'showOn'=>'button', // 'focus', 'button', 'both'
'buttonText'=>Yii::t('ui','Select form calendar'),
'buttonImage'=>Yii::app()->baseUrl.'/images/calendar.png',
'buttonImageOnly'=>true,