Featured Posts

FuelPHP Command Line Oil with Windows BAT File And... I have been using the Codeigniter PHP MVC framework for awhile now and have started to realize I need some extra features that are not built in by default.  A few weeks ago...

Readmore

PHP Class To Build HTML Forms I have recently pushed a new repository to Github to showcase a PHP class I built.  This class helps make building HTML forms easier.  I originally built this class to help...

Readmore

Codeigniter Library to Read CSV File I recently posted some code to Github that I created for use in Codeigniter. I built a library that can be used to read CSV files, extract the data you need, and return a...

Readmore

Using PHP Curl To Check Apple Site To See If My Extension... A few weeks ago (probably closer to months now) I built a Safari extension.  I also submitted it to Apple to see if it can be listed on their Safari extensions page.  I...

Readmore

Safari Extensions - Puni.co URL Redirection For anyone interested in URL redirection services and Safari Extensions, here is a service offered by TheBizzTech LLC.  We have made a Safari Extension that uses the free puni.co...

Readmore

TheBizzTech Rss

PHP Class To Build HTML Forms

Posted on : 29-04-2011 | By : TheBizzTech | In : Github, HTML, PHP, Programming

Tags: , , , , ,

4

I have recently pushed a new repository to Github to showcase a PHP class I built.  This class helps make building HTML forms easier.  I originally built this class to help make PayPal buttons easier to built into PHP scripts.  I have not looked at this script much since the summer of 2010, but hope to dust it off soon.

Here is a simple example of how to use the class that you can download from Github here, https://github.com/thebizztech/htmlform


<?php
/**
* TheBizzTech
*
* This example utilizes the open source htmlform PHP class built to make building HTML forms easier
*
* @author		Jason Michels
* @link		http://thebizztech.com
*/

//To use the htmlform class you first need to include the file
require("htmlform.php");
?>
<html>
<body>
<?php
// Initialize form class
$form = new htmlform();
// Begin the form and pass array of values
$form->begin_form(array("name"=>"myform","action"=>"index.php","method"=>"post","target"=>"thebizztech"));

// To create a new label include the element id in the "for" array value
$form->form_label(array("for"=>"1stid","text"=>"This is a label: "));

// To create an input field pass array with any standard attributes. The class will check to see which ones are set
$form->form_input(array("type"=>"text","id"=>"1stid","class"=>"1stclass","name"=>"1stname","value"=>"this is the value"));

// Another form input example
$form->form_input(array("type"=>"submit","id"=>"submitform","class"=>"submitform","name"=>"submit","value"=>"Submit Form"));

// Example of a form button
$form->form_button(array("type"=>"button","value"=>"Awesome","text"=>"Awesome button"));

// End of form. This will take one parameter allowing you to add html after the form such as a line in the example
$form->end_form("<hr />");
?>
</body>
</html>

Codeigniter Library to Read CSV File

Posted on : 26-04-2011 | By : TheBizzTech | In : Codeigniter, Github, Model-View-Controller (MVC), PHP

Tags: , , ,

8

I recently posted some code to Github that I created for use in Codeigniter. I built a library that can be used to read CSV files, extract the data you need, and return a PHP associative array.

Below I will post the code and a simple function that could be used in a Controller that would utilize the library.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * TheBizzTech
 *
 * An open source library built for Codeigniter to read CSV files into associated arrays
 *
 * @author		Jason Michels
 * @link		http://thebizztech.com
 */

class Getcsv {

	function get_csv_assoc_array($file_path, $questions)
	{
		$row = 0;
		if (($handle = fopen($file_path, "r")) !== FALSE)
		{
			while (($data = fgetcsv($handle, "", ",")) !== FALSE)
			{
				if($row == 0)
				{
					foreach ($questions as $key => $value)
					{
						foreach($data as $d_key => $d_value)
						{
							if($data[$d_key] == $value)
							{
								$q_location[$value] = $d_key;
							}
						}
					}
				}
				else
				{
					foreach ($questions as $key => $value)
					{
						$new_row = $row -1;
						$final_array[$new_row][$value] = $data[$q_location[$value]];
					}
				}

				$row++;
			}
			fclose($handle);
		}
		return $final_array;

	}
}

?>

Here is the example function:

function sample_read_csv()
{
	$this->load->library('getcsv');

	$data = array('name', 'email', 'id', 'transaction');

	$csv_array = $this->getcsv->get_csv_assoc_array("path/to/file.csv", $data);
	print_r($csv_array);
}

Right now this library only has one way of reading CSV files, but I hope to expand it over time.

To use the library you first have to load the library:

$this->load->library('getcsv');

After the library is loaded you have to create an array of column names that you know are in the CSV file and would like returned. Finally, call the library function and pass in the path to the file and the array you created, then print to see the results.

$data = array('name', 'email', 'id', 'transaction');
$csv_array = $this->getcsv->get_csv_assoc_array("path/to/file.csv", $data);
print_r($csv_array);

Let me know if there is any features you would like to see. You can find this code hosted on Github HERE.