PHP – Read CSV Data into PHP Array

First post for a while! The website will be updated more regularly now though. Here is a quick PHP snippet that will read CSV data from a file specified and return a Multidimensional Array with keys based on column names.

	private function __readCSV($fileName) {
			$file = fopen($fileName, 'r'); 
			$fields = array();
			$CSVdata = array();
			if ($file) {
				while (($data = fgetcsv($file)) !== false) {
					if(empty($fields)) {
						$fields = $data;

					$row = array_combine($fields, $data);
					$CSVdata[] = $row;
				unset($file, $row, $data, $fields);
				return $CSVdata;

Just call the function with the full path to the file. Any questions then leave a comment below. Enjoy.

PHP – Custom MVC Framework with Smarty3 and ActiveRecords

After using a few different PHP MVC’s I decided to work on my own framework when I had some spare time. Over the past few days I’ve put together a lightweight and feature rich small PHP MVC Framework. Note that it should currently be considered beta software, It should be useful for anyone wanting to develop their own MVC framework, feel free to use this as a base for your own framework or projects.

Read More

PHP – Useful TinyMVC View Helpers

Back again with more TinyMVC code. As I get more into this framework the more code I’ll be posting up, the functions in the code below are to be used directly from TinyMVC views and not controllers or models.

One of the most useful features below is block($view) allowing you to directly output other views, inside your view (like CakePHP does) although this is technically not following “strict” MVC guidelines it is still a very useful feature.

Read More

PHP – TinyMVC Template Wrapper Plugin

TinyMVC provides a great structure for developing new projects, it’s small base allows the developer to write new plug-ins and extend on the existing framework. Below you’ll find a template wrapper I have made to manage the views and assigning of data. The class allows you to set a default view to be used in order to keep consistency throughout; so that you can minimize view code in the controllers.

Read More