Pages

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Saturday, March 19, 2011

CI - Date Parser

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * This class will provide parsing service for date time format:
 * month/date/year and hour:minute:second
 *
 * @author   : irfanudin ridho
 * @email    : irfan.ub@gmail.com
 * @version  : 1.0
 * @date     : February 20, 2011
 */

class Parser {

    function parsee($data)
    {
        $this->datee = $data['date'];
        $this->timee = $data['time'];
       
        $this->date = array();
        foreach(explode('/',$this->datee) as $value){
            $this->date[] = $value;
        }
       
        $this->time = array();
        foreach(explode(':', $this->timee) as $value){
            $this->time[] = $value;
        }
       
    }
   
    function get_date(){
        return $this->date[1];
    }
   
    function get_month(){
        return $this->date[0];
    }
   
    function get_year(){
        return $this->date[2];
    }
   
    function get_hour(){
        return $this->time[0];
    }
   
    function get_minute(){
        return $this->time[1];
    }
   
    function get_second(){
        return $this->time[2];
    }
}

?>

Friday, March 18, 2011

PHP - Using SQLite3

/**
 * index.php
 */

<html>
<head>
<script src="jquery.js"></script>
<script>
function save(){
    var ajax = new XMLHttpRequest();
    var name = document.getElementById('name');
    var city = document.getElementById('city');
    var age = document.getElementById('age');
    var mode = 'write';
    

Tuesday, January 11, 2011

Writing XML Document

/**
 * This class provide framework on how to write to xml file.
 * <?xml version="1.0"?>
 * <data>
 *    <entry>
 *        <name>...</name>
 *        <city>...</city>
 *    </entry>
 * </data>
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : january 11, 2010
 * @version : 1.0
 */


class XMLWrite{
   
    /** 
     * constructor service
     * @param filename of the xml document
     */
    public function __construct($file){
        $this->file = $file;
        $this->contents = file_get_contents($this->file);

    }

    /**
     * a method to insert the data to the xml document
     * @param the first text element
     * @param the second text element
     */
    public function insert($name,$city){
        $this->contents = str_replace("</data>","",
                                      $this->contents);
        $new_contents = $this->contents
                        ."<entry><name>".$name."</name>"
                        ."<city>".$city."</city></entry></data>";
        file_put_contents($this->file,$new_contents);
    }
}

Saturday, December 18, 2010

MySQL Result As An Array

/**
* @author irfanudin ridho
* @email irfan.ub@gmail.com
* @data december 18, 2010
* @version 1.0
*
* This function will convert mysql resource from 
* mysql_query() to 2D array.
*
* @param $resouce return value from mysql_query();
* @return $arrData 2D array
**/

function toArray($resource){
    $arrData = array();
    $i = 0;
    while($row=mysql_fetch_array($resource)){
        for($j=0;$j<mysql_num_fields($resource);$j++){
            $arrData[$i][$j] = $row[$j];
        }
        $i++;
    }
    return $arrData;
}