<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Redink Design &#187; PHP</title>
	<atom:link href="http://redinkdesign.net/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://redinkdesign.net</link>
	<description>Good code is its own best documentation</description>
	<lastBuildDate>Fri, 06 Jan 2012 22:25:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adding a Link in a SugarCRM Dashlet</title>
		<link>http://redinkdesign.net/programming/adding-a-link-in-a-sugarcrm-dashlet/</link>
		<comments>http://redinkdesign.net/programming/adding-a-link-in-a-sugarcrm-dashlet/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 20:15:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SugarCRM]]></category>

		<guid isPermaLink="false">http://redinkdesign.net/?p=155</guid>
		<description><![CDATA[I&#8217;m going to use the Tasks Module as an example. I will link the &#8216;Contact&#8217; field to the contacts module detail view.
Open /modules/Tasks/Dashlets/MyTasksDashlet/MyTasksDashlet.data.php
Initially it looks like this:


'contact_name' =&#62; array(
 'width'   =&#62; '8',
 'label'   =&#62; 'LBL_LIST_CONTACT'
),

To make this field link to the contacts module:

'contact_name' =&#62; array(
 'width'   =&#62; '8',
 'label'   =&#62; 'LBL_LIST_CONTACT',
 ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to use the Tasks Module as an example. I will link the &#8216;Contact&#8217; field to the contacts module detail view.</p>
<p>Open /modules/Tasks/Dashlets/MyTasksDashlet/MyTasksDashlet.data.php</p>
<p>Initially it looks like this:</p>
<pre class="brush: php;">

'contact_name' =&gt; array(
 'width'   =&gt; '8',
 'label'   =&gt; 'LBL_LIST_CONTACT'
),
</pre>
<p>To make this field link to the contacts module:</p>
<pre class="brush: php;">
'contact_name' =&gt; array(
 'width'   =&gt; '8',
 'label'   =&gt; 'LBL_LIST_CONTACT',
 'link' =&gt; true,
 'action' =&gt; 'DetailView',
 'module' =&gt; 'Contacts',
 'id' =&gt; 'CONTACT_ID',
 'related_fields' =&gt; array('contact_id')
 ),
</pre>
<p>The main fields are:<br />
link: True/False<br />
module: The name of the destination module<br />
action: DetailView or EditView<br />
id: The field that contains the ID for the related field. If it doesn&#8217;t work lower case, try it in uppercase<br />
related_fields: The field that contains the relation ID &#8211; This should be the same as &#8216;id&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://redinkdesign.net/programming/adding-a-link-in-a-sugarcrm-dashlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP MSSQL Class</title>
		<link>http://redinkdesign.net/programming/ms-sql-class/</link>
		<comments>http://redinkdesign.net/programming/ms-sql-class/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 16:03:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This code is still beta, use at your own risk.

<code>

__db_host = $host;
			$this-&#62;__db_username = $username;
			$this-&#62;__db_password = $password;
			$this-&#62;__db_name = $db_name;

			$this-&#62;connect();
		}

		/**
		 * Initialize our table object
]]></description>
			<content:encoded><![CDATA[<p>This code is still beta, use at your own risk.</p>
<pre class="brush: php;">
&lt;?php
/**
	All code is Copyright 2009 by Ashwin Surajbali (http://www.redinkdesign.net).

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation.

	This program is distributed in the hope that it will be useful, but
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
	for more details.

	You can view a copy of the GNU General Public Licsense at

http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

**/

	class redDB {

		private $__db_host;
		private $__db_username;
		private $__db_password;
		private $__db_name;
		private $__db_handle;

		private $__sql;
		private $__table_name;
		private $__result;

		function __construct($host, $username, $password, $db_name, $db_handle = ''){

			if (empty($db_handle)){
				$this-&gt;__db_host = $host;
				$this-&gt;__db_username = $username;
				$this-&gt;__db_password = $password;
				$this-&gt;__db_name = $db_name;
				$this-&gt;connect();
			}else{
				$this-&gt;__db_handle = $db_handle;
			}
		}

		/**
		 * Initialize our table object
		 *
		 * @example $this-&gt;init('users_table');
		 *
		 * @param string $table
		 * @return object
		 */
		public function init($table = ''){
			if(empty($table)){
				$this-&gt;throw_error(__METHOD__, __LINE__, 'No table name specified.');
			}

			$this-&gt;__table_name = $table;

			$ar_fields = $this-&gt;get_table_fields();

			if (!is_array($ar_fields)) {
				$this-&gt;throw_error(__METHOD__, __LINE__, &quot;ERROR: Table '{$this-&gt;__table_name}' has no fields.&quot;);
			}

			foreach ($ar_fields as $field){

				switch ($field-&gt;type){
					case &quot;INTEGER&quot;:
					case &quot;TINYINT&quot;:
					case &quot;SMALLINT&quot;:
					case &quot;MEDIUMINT&quot;:
						$this-&gt;{$field-&gt;name} = 0;
						break;
					case &quot;NUMERIC&quot;:
					case &quot;FLOAT&quot;:
					case &quot;DECIMAL&quot;:
						$this-&gt;{$field-&gt;name} = 0.00;
						break;
					default:
						$this-&gt;{$field-&gt;name} = '';
						break;
				}

				if (!empty($field-&gt;def)) {
					$this-&gt;{$field-&gt;name} = $field-&gt;def;
				}

			}

			return $this;
		}

		/**
		 * Alias for @link init
		 *
		 * @param string $table
		 * @return object
		 */
		public function init_table($table){
			return $this-&gt;init($table);
		}

		/**
		 * Returns a single record as a table object depending on
		 * constraint passed in
		 *
		 * @example $this-&gt;get_single_record(&quot;id = 22&quot;);
		 *
		 * @param string $constraint
		 * @return object
		 */
		public function get_single_record($constraint = ''){
			if (empty($this-&gt;__table_name)){
				$this-&gt;throw_error(__METHOD__, __LINE__,  &quot;You must initialize a table before retrieving a record.&quot;);
			}

			if (empty($constraint)){
				$this-&gt;throw_error(__METHOD__, __LINE__,  &quot;No constraint entered.&quot;);
			}

			$this-&gt;__sql = &quot;select top 1 * from {$this-&gt;__table_name} where {$constraint}&quot;;
			return $this-&gt;get_single_result();

		}

		/**
		 * Alias for @link get_single_record
		 *
		 * @param string $constraint
		 * @return object
		 */
		public function get($constraint){
			return $this-&gt;get_single_record($constraint);
		}

		/**
		 * Inserts a new record or updates if it already exists
		 * Use this for quick updates/inserts
		 *
		 * For custom updates, use @link update
		 *
		 * @return boolean
		 */
		public function save(){

			$duplicate_sql = '';
			$this-&gt;__sql = &quot;insert into {$this-&gt;__table_name} values (&quot;;
			foreach ($this as $key =&gt; $val){
				if (substr($key, 0, 2) == '__'){
					continue;
				}
				$this-&gt;__sql .= &quot;'{$this-&gt;escape($val)}'&quot; . ',';
			}
			$this-&gt;__sql = trim($this-&gt;__sql, ',');
			$this-&gt;__sql .= &quot;)&quot;;

			return $this-&gt;execute_query($this-&gt;__sql);
		}

		public function insert(){
			return $this-&gt;save();
		}

		/**
		 * Updates an existing record depending on custom constraints
		 * Use this for complex updates instead of @link save
		 *
		 * @param string $where_constraint
		 * @return boolean
		 */
		public function update($where_constraint = ''){
			if (empty($where_constraint)){
				$this-&gt;throw_error(__METHOD__, __LINE__, 'Missing WHERE constraint. eg. ID = 222');
			}

			$this-&gt;__sql = &quot;update {$this-&gt;__table_name} set &quot;;
			foreach ($this as $key =&gt; $val){
				if (substr($key, 0, 2) == '__'){
					continue;
				}
				$this-&gt;__sql .= &quot;{$key} = '{$this-&gt;escape($val)}'&quot; . ',';
			}
			$this-&gt;__sql = trim($this-&gt;__sql, ',');
			$this-&gt;__sql .= ' where ' . $where_constraint;

			return $this-&gt;execute_query($this-&gt;__sql);
		}

		/**
		 * Executes a query
		 *
		 * @param string $query
		 * @return boolean
		 */
		public function execute_query($query){
			$this-&gt;__sql = $query;
			if(!$this-&gt;query($this-&gt;__sql)){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}
			return true;
		}

		/**
		 * Send out a query and return the first field of the first result row
		 * eg. select count(*) as count from blah; only the value of count will be returned
		 *
		 * @param string $query
		 * @return string return value of query
		 */
		public function get_query_value($query){
			if (empty($query)) $this-&gt;throw_error(__METHOD__, __LINE__, 'Query missing.');

			$this-&gt;__sql = $query;
			$this-&gt;__result = $this-&gt;query($this-&gt;__sql);
			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ar_result = mssql_fetch_array($this-&gt;__result);
			if (!empty($ar_result[0])){
				return $ar_result[0];
			}else{
				return false;
			}
		}

		/**
		 * Get data from the initialized table depending on constraint, limit and order
		 * Returns results in an array of objects
		 *
		 * @param string $constraint - optional
		 * @param string $limit - optional
		 * @param string $order_by - optional
		 * @return array of objects
		 */
		public function get_data($constraint = '', $limit = '', $order_by = ''){
			if (empty($this-&gt;__table_name)) $this-&gt;throw_error(__METHOD__, __LINE__, 'Table missing.');

			$this-&gt;__sql = &quot;select &quot; . (!empty($limit)? &quot; top {$this-&gt;escape($limit)}&quot; : '') . &quot; * from {$this-&gt;__table_name}&quot; . (!empty($constraint)? &quot; where {$constraint}&quot; : '') . (!empty($order_by)? &quot; order by {$this-&gt;escape($order_by)}&quot; : '');
			$this-&gt;__result = $this-&gt;query($this-&gt;__sql);
			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ar_results = array();
			while($obj = mssql_fetch_object($this-&gt;__result)){
				$ar_results[] = $obj;
			}

			if (is_array($ar_results)){
				return $ar_results;
			}else{
				return false;
			}
		}

		/**
		 * Runs a query and returns results in an array of objects
		 *
		 * @param string $query
		 * @return array
		 */
		public function get_query_data($query){
			if (empty($query)) $this-&gt;throw_error(__METHOD__, __LINE__, &quot;Query missing.&quot;);

			$this-&gt;__sql = $query;
			$this-&gt;__result = $this-&gt;query($this-&gt;__sql);
			if(!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ar_results = array();
			while ($obj = mssql_fetch_object($this-&gt;__result)){
				$ar_results[] = $obj;
			}

			if (is_array($ar_results)){
				return $ar_results;
			}else{
				return false;
			}
		}

		/**
		 * Escapes special characters in a string for use in a SQL statement
		 *
		 * @param string $string
		 * @return string
		 */
		public function escape($string){
			return str_replace(&quot;'&quot;, &quot;''&quot;, $string);
		}

		/**
		 * Gets the sql statement that was executed
		 *
		 * @return string
		 */
		public function get_sql(){
			return $this-&gt;__sql;
		}

		/**
		 * Gets the number of rows in a result
		 *
		 * @return int
		 */
		public function get_num_rows(){
			return mssql_num_rows($this-&gt;__result);
		}

		/**
		 * Gets the number of affected rows in a previous MySQL operation
		 * Returns an integer greater than zero which indicated the number of rows affected or retrieved.
		 * Zero indicates that no records where updated for an UPDATE statement,
		 * no rows matched the WHERE clause in the query or that no query has yet been executed.
		 * -1 indicates that the query returned an error.
		 *
		 * @return int
		 */
		public function get_affected_rows(){
			return mssql_rows_affected($this-&gt;__db_handle);
		}

		private function connect(){
			if (!$this-&gt;__db_handle = mssql_connect($this-&gt;__db_host, $this-&gt;__db_username, $this-&gt;__db_password)){
				$this-&gt;throw_error(__METHOD__, __LINE__, 'Could not connect to SQL server.');
			}

			if (!mssql_select_db($this-&gt;__db_name, $this-&gt;__db_handle)){
				$this-&gt;throw_error(__METHOD__, __LINE__, 'Could not select database ' . $this-&gt;__db_name);
			}
		}

		private function get_single_result(){
			$this-&gt;__result = $this-&gt;query($this-&gt;__sql);
			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ob_record = mssql_fetch_object($this-&gt;__result);
			if (is_object($ob_record)){
				foreach($ob_record as $key =&gt; $value){
					$this-&gt;{$key} = $value;
				}
				return $this;
			}else{
				return false;
			}
		}

		private function get_table_fields(){
			$this-&gt;__sql = &quot;select top 1 * from {$this-&gt;escape($this-&gt;__table_name)}&quot;;

			$this-&gt;__result = mssql_query($this-&gt;__sql, $this-&gt;__db_handle);

			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__,'Could not fetch table fields.');
			}

			for ($i = 0; $i &lt; mssql_num_fields($this-&gt;__result); $i++){
				$field = mssql_fetch_field($this-&gt;__result, $i);
				$ar_fields[$field-&gt;name]-&gt;name = $field-&gt;name;
				$ar_fields[$field-&gt;name]-&gt;type = strtoupper($field-&gt;type);
				$ar_fields[$field-&gt;name]-&gt;max_length = $field-&gt;max_length;
				$ar_fields[$field-&gt;name]-&gt;column_source = $field-&gt;column_source;
				$ar_fields[$field-&gt;name]-&gt;numeric = $field-&gt;numeric;
			}

			if (count($ar_fields) &gt; 0){
				return $ar_fields;
			}else{
				$this-&gt;throw_error(__METHOD__, __LINE__, &quot;No columns found for table {$this-&gt;__table_name}.&quot;);
			}

		}

		private function query($query){
			$this-&gt;__result = mssql_query($query, $this-&gt;__db_handle);
			return $this-&gt;__result;
		}

		private function throw_error($function_name, $line_number, $error_msg = ''){
			die('&lt;font style=&quot;color: red; font-weight: bold;&quot;&gt;-- Error --&lt;/font&gt;&lt;br /&gt;' . $function_name . ' at line ' . $line_number . '&lt;br /&gt;' . (!empty($error_msg)? &quot;&lt;br /&gt;Message: $error_msg&quot; : &quot;Invalid Query: {$this-&gt;__sql}&quot;));
		}

	}
?&gt;
</pre>
<p>All code is Copyright 2009 by Ashwin Surajbali (http://www.redinkdesign.net).</p>
<p>This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation.</p>
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.</p>
<p>You can view a copy of the GNU General Public Licsense at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.</p>
]]></content:encoded>
			<wfw:commentRss>http://redinkdesign.net/programming/ms-sql-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QuantCast Screen Scraper</title>
		<link>http://redinkdesign.net/programming/php/quantcast-screen-scraper/</link>
		<comments>http://redinkdesign.net/programming/php/quantcast-screen-scraper/#comments</comments>
		<pubDate>Wed, 13 May 2009 15:31:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This is a quick and dirty screen scraper for quantcast.com. It currently only grabs the site rank and description.

Usage:
<code>
		$q = new QuantCast('cnet.com');
		echo '<strong>Rank:</strong> ' . $q-&#62;getRank() . '<br />';
		echo '<strong>Desc:</strong> ' . $q-&#62;getDescription() . '<br />';
</code>

Class Source Code:
<code>
	class QuantCast {

		public $siteName;
		private $siteContents;

		public function __construct($siteName){
			$this-&#62;siteName = strtolower(str_replace('http://', '', $siteName));
]]></description>
			<content:encoded><![CDATA[<p>This is a quick and dirty screen scraper for quantcast.com. It currently only grabs the site rank and description.</p>
<p><strong>Updated: 8/10/2010<br />
Rank, Description and US Stats are now working again. Global Stats are no longer available.</strong></p>
<p><strong>Usage:</strong></p>
<pre class="brush: php;">
$q = new QuantCast('cnet.com');
		echo '&lt;strong&gt;Rank:&lt;/strong&gt; ' . $q-&gt;getRank() . '&lt;br /&gt;';
		echo '&lt;strong&gt;Desc:&lt;/strong&gt; ' . $q-&gt;getDescription() . '&lt;br /&gt;';
</pre>
<p><strong><br />
Class Source Code:</strong></p>
<pre class="brush: php;">
class QuantCast {

 public $siteName;
 public $rank = 0;
 public $description = '';
 public $usTraffic = '';

 private $siteContents;

 public function __construct($siteName){

 $this-&gt;siteName = strtolower(str_replace('http://', '', $siteName));
 $url = &quot;http://www.quantcast.com/{$this-&gt;siteName}&quot;;

 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_USERAGENT, &quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729)&quot;);
 $this-&gt;siteContents = curl_exec($ch);
 curl_close($ch);

 $newlines = array(&quot;\t&quot;,&quot;\n&quot;,&quot;\r&quot;,&quot;\x20\x20&quot;,&quot;&#92;&#48;&quot;,&quot;\x0B&quot;);
 $this-&gt;siteContents = str_replace($newlines, &quot;&quot;, html_entity_decode($this-&gt;siteContents));
 }

 public function getRank(){
 $this-&gt;_getRank();
 return $this-&gt;rank;
 }

 public function getDescription(){
 $this-&gt;_getDescription();
 return $this-&gt;description;
 }

 public function getUsStats(){
 $this-&gt;_getUsStats();
 return $this-&gt;usTraffic;
 }

 private function _getRank(){
 $start = strpos($this-&gt;siteContents, '&lt;li&gt;');
 $end = strpos($this-&gt;siteContents, '&lt;/li&gt;', $start);
 $data = substr($this-&gt;siteContents, $start, $end-$start);
 preg_match_all('/\&lt;strong\&gt;([0-9,]*)\&lt;\/strong\&gt;/', $data, $ar_matches);
 $this-&gt;rank = $ar_matches[1][0];
 }

 private function _getDescription(){
 $start = strpos($this-&gt;siteContents, '&lt;div&gt;');
 $end = strpos($this-&gt;siteContents, '&lt;/div&gt;', $start);
 $data = substr($this-&gt;siteContents, $start, $end-$start);
 $this-&gt;description = strip_tags($data);
 }

 private function _getUsStats(){
 $site = explode('.', $this-&gt;siteName);
 $td = '&lt;td id=&quot;reach-wd:' . $site[1] . '.' . $site[0] . '&quot;&gt;';
 $start = strpos($this-&gt;siteContents, $td);
 $end = strpos($this-&gt;siteContents, '&lt;/td&gt;', $start);
 $data = substr($this-&gt;siteContents, $start, $end-$start);
 $data = strip_tags($data);
 $data = str_replace('Est.MonthlyUS People', '', $data);
 $this-&gt;usTraffic = $data;
 }
 }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://redinkdesign.net/programming/php/quantcast-screen-scraper/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP MySQLi Table to Object Class</title>
		<link>http://redinkdesign.net/programming/php/php-mysqli-table-to-object-class/</link>
		<comments>http://redinkdesign.net/programming/php/php-mysqli-table-to-object-class/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 13:00:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This class requires PHP 5.2+ and the MySQLi extension. It will not work with the regular MySQL extension.  An object representing a table is created on the fly that will allow you to do inserts, updates etc. 

Please see comments in the code for usage. 

<code>
init('user_table');
	 * 	$user-&#62;get("user_id = 4343");
]]></description>
			<content:encoded><![CDATA[<p>This class requires PHP 5.2+ and the MySQLi extension. It will not work with the regular MySQL extension.  An object representing a table is created on the fly that will allow you to do inserts, updates etc. </p>
<p>Please see comments in the code for usage. </p>
<pre class="brush: php;">
&lt;?php
/**
	All code is Copyright 2009 by Ashwin Surajbali (http://www.redinkdesign.net).

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation.

	This program is distributed in the hope that it will be useful, but
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
	for more details.

	You can view a copy of the GNU General Public Licsense at

http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

**/

	/**
	 * Create's an object representing a table in a database
	 * This class requires a database handle to be passed in
	 *
	 * @version 1.0
	 *
	 * @example
	 * 	$db = new redDB('host', 'username', 'password', 'database_name');
	 * 	$user = $db-&gt;init('user_table');
	 * 	$user-&gt;get(&quot;user_id = 4343&quot;);
	 * 	$user-&gt;name = 'BumbleBee';
	 * 	$user-&gt;save();
	 *
	 * @example
	 * 	$db = new redDB('host', 'username', 'password', 'database_name');
	 * 	$user = $db-&gt;init('user_table');
	 * 	$user-&gt;name = 'BumbleBee';
	 * 	$user-&gt;age = 24;
	 * 	$user-&gt;save();
	 *
	 * @example
	 * 	$db = new redDB('host', 'username', 'password', 'database_name');
	 * 	$user = $db-&gt;init('user_table');
	 * 	$user-&gt;get(&quot;user_id = 1233&quot;);
	 * 	$user-&gt;name = '
	 * 	$user-&gt;sex = 'F';
	 * 	$user-&gt;update(&quot;sex != 'F' &amp;&amp; user_id = 1233&quot;);
	 *
	 * @example
	 * 	$db = new redDB('host', 'username', 'password', 'database_name');
	 * 	$user = $db-&gt;init('user_table');
	 * 	$ar_users = $user-&gt;get_data(&quot;first_name = 'john'&quot;);
	 * 	foreach ($ar_users as $user){
	 * 		echo $user-&gt;id;
	 * 	}
	 *
	 * @example
	 * 	$db = new redDB('host', 'username', 'password', 'database_name');
	 * 	$user = $db-&gt;init('user_table');
	 * 	$ar_all_users = $user-&gt;get_data();
	 * 	foreach ($ar_all_users as $user){
	 * 		echo $user-&gt;age . '&lt;br /&gt;';
	 *	}
	 *
	 * @example
	 * 	$db = new redDB('host', 'username', 'password', 'database_name');
	 * 	$first_name = $db-&gt;get_query_value(&quot;select first_name from user_table where id = 12333&quot;);
	 *
	 * @example
	 * 	$db = new redDB('host', 'username', 'password', 'database_name');
	 * 	$ar_data = $db-&gt;get_query_data(&quot;select * from user_table where age &gt; 21&quot;);
	 * 	foreach ($ar_data as $data){
	 * 		echo $data-&gt;first_name . '&lt;br /&gt;';
	 * 	}
	 *
	 */

	class redDB {

		private $__db_host;
		private $__db_username;
		private $__db_password;
		private $__db_name;
		private $__db_port;
		private $__db_handle;

		private $__sql;
		private $__table_name;
		private $__primary_key = '';
		private $__result;
		private $__ar_field_types = array(
			0 =&gt; &quot;DECIMAL&quot;,
			1 =&gt; &quot;TINYINT&quot;,
			2 =&gt; &quot;SMALLINT&quot;,
			3 =&gt; &quot;INTEGER&quot;,
			4 =&gt; &quot;FLOAT&quot;,
			5 =&gt; &quot;DOUBLE&quot;,
			7 =&gt; &quot;TIMESTAMP&quot;,
			8 =&gt; &quot;BIGINT&quot;,
			9 =&gt; &quot;MEDIUMINT&quot;,
			10 =&gt; &quot;DATE&quot;,
			11 =&gt; &quot;TIME&quot;,
			12 =&gt; &quot;DATETIME&quot;,
			13 =&gt; &quot;YEAR&quot;,
			14 =&gt; &quot;DATE&quot;,
			16 =&gt; &quot;BIT&quot;,
			246 =&gt; &quot;DECIMAL&quot;,
			247 =&gt; &quot;ENUM&quot;,
			248 =&gt; &quot;SET&quot;,
			249 =&gt; &quot;TINYBLOB&quot;,
			250 =&gt; &quot;MEDIUMBLOB&quot;,
			251 =&gt; &quot;LONGBLOB&quot;,
			252 =&gt; &quot;BLOB&quot;,
			253 =&gt; &quot;VARCHAR&quot;,
			254 =&gt; &quot;CHAR&quot;,
			255 =&gt; &quot;GEOMETRY&quot;
		);

		function __construct($host, $username, $password, $db_name, $port = '3306'){

			$this-&gt;__db_host = $host;
			$this-&gt;__db_username = $username;
			$this-&gt;__db_password = $password;
			$this-&gt;__db_name = $db_name;
			$this-&gt;__db_port = $port;
			$this-&gt;connect();
		}

		/**
		 * Initialize our table object
		 *
		 * @example $this-&gt;init('users_table');
		 *
		 * @param string $table
		 * @return object
		 */
		public function init($table = ''){
			if(empty($table)){
				$this-&gt;throw_error(__METHOD__, __LINE__, 'No table name specified.');
			}

			$this-&gt;__table_name = $table;

			$ar_fields = $this-&gt;get_table_fields();

			if (!is_array($ar_fields)) {
				$this-&gt;throw_error(__METHOD__, __LINE__, &quot;ERROR: Table '{$this-&gt;__table_name}' has no fields.&quot;);
			}

			foreach ($ar_fields as $field){

				switch ($field-&gt;type){
					case &quot;INTEGER&quot;:
					case &quot;TINYINT&quot;:
					case &quot;SMALLINT&quot;:
					case &quot;MEDIUMINT&quot;:
						$this-&gt;{$field-&gt;name} = 0;
						break;
					case &quot;DOUBLE&quot;:
					case &quot;FLOAT&quot;:
					case &quot;DECIMAL&quot;:
						$this-&gt;{$field-&gt;name} = 0.00;
						break;
					case &quot;DATE&quot;:
						$this-&gt;{$field-&gt;name} = '0000-00-00';
						break;
					case &quot;TIME&quot;:
						$this-&gt;{$field-&gt;name} = '00:00:00';
						break;
					case &quot;DATETIME&quot;:
						$this-&gt;{$field-&gt;name} = '0000-00-00 00:00:00';
						break;
					case &quot;YEAR&quot;:
						$this-&gt;{$field-&gt;name} = '0000';
						break;
					default:
						$this-&gt;{$field-&gt;name} = '';
						break;
				}

				if (!empty($field-&gt;def)) {
					$this-&gt;{$field-&gt;name} = $field-&gt;def;
				}

			}

			return $this;
		}

		/**
		 * Alias for @link init
		 *
		 * @param string $table
		 * @return object
		 */
		public function init_table($table){
			return $this-&gt;init($table);
		}

		/**
		 * Returns a single record as a table object depending on
		 * constraint passed in
		 *
		 * @example $this-&gt;get_single_record(&quot;id = 22&quot;);
		 *
		 * @param string $constraint
		 * @return object
		 */
		public function get_single_record($constraint = ''){
			if (empty($this-&gt;__table_name)){
				$this-&gt;throw_error(__METHOD__, __LINE__,  &quot;You must initialize a table before retrieving a record.&quot;);
			}

			if (empty($constraint)){
				$this-&gt;throw_error(__METHOD__, __LINE__,  &quot;No constraint entered.&quot;);
			}

			$this-&gt;__sql = &quot;select * from {$this-&gt;__table_name} where {$constraint} limit 1&quot;;
			return $this-&gt;get_single_result();

		}

		/**
		 * Alias for @link get_single_record
		 *
		 * @param string $constraint
		 * @return object
		 */
		public function get($constraint){
			return $this-&gt;get_single_record($constraint);
		}

		/**
		 * Inserts a new record or updates if it already exists
		 * Use this for quick updates/inserts
		 *
		 * For custom updates, use @link update
		 *
		 * @return boolean
		 */
		public function save(){

			$duplicate_sql = '';
			$this-&gt;__sql = &quot;insert into {$this-&gt;__table_name} values (&quot;;
			foreach ($this as $key =&gt; $val){
				if (substr($key, 0, 2) == '__'){
					continue;
				}
				$this-&gt;__sql .= &quot;'{$this-&gt;escape($val)}'&quot; . ',';
				$duplicate_sql .= &quot;{$key} = '{$this-&gt;escape($val)}'&quot; . ',';
			}
			$this-&gt;__sql = trim($this-&gt;__sql, ',');
			$this-&gt;__sql .= &quot;)&quot;;
			$this-&gt;__sql .= ' on duplicate key update ';
			$this-&gt;__sql .= trim($duplicate_sql, ',');

			return $this-&gt;execute_query($this-&gt;__sql);
		}

		/**
		 * Updates an existing record depending on custom constraints
		 * Use this for complex updates instead of @link save
		 *
		 * @param string $where_constraint
		 * @return boolean
		 */
		public function update($where_constraint = ''){
			if (empty($where_constraint)){
				$this-&gt;throw_error(__METHOD__, __LINE__, 'Missing WHERE constraint. eg. ID = 222');
			}

			$this-&gt;__sql = &quot;update {$this-&gt;__table_name} set &quot;;
			foreach ($this as $key =&gt; $val){
				if (substr($key, 0, 2) == '__'){
					continue;
				}
				$this-&gt;__sql .= &quot;{$key} = '{$this-&gt;escape($val)}'&quot; . ',';
			}
			$this-&gt;__sql = trim($this-&gt;__sql, ',');
			$this-&gt;__sql .= ' ' . $where_constraint;

			return $this-&gt;execute_query($this-&gt;__sql);
		}

		/**
		 * Executes a query
		 *
		 * @param string $query
		 * @return boolean
		 */
		public function execute_query($query){
			$this-&gt;__sql = $query;
			if(!$this-&gt;__db_handle-&gt;query($this-&gt;__sql)){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}
		}

		/**
		 * Send out a query and return the first field of the first result row
		 * eg. select count(*) as count from blah; only the value of count will be returned
		 *
		 * @param string $query
		 * @return string return value of query
		 */
		public function get_query_value($query){
			if (empty($query)) $this-&gt;throw_error(__METHOD__, __LINE__, 'Query missing.');

			$this-&gt;__sql = $query;
			$this-&gt;__result = $this-&gt;__db_handle-&gt;query($this-&gt;__sql);
			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ar_result = $this-&gt;__result-&gt;fetch_array();
			if (!empty($ar_result[0])){
				return $ar_result[0];
			}else{
				return false;
			}
		}

		/**
		 * Get data from the initialized table depending on constraint, limit and order
		 * Returns results in an array of objects
		 *
		 * @param string $constraint - optional
		 * @param string $limit - optional
		 * @param string $order_by - optional
		 * @return array of objects
		 */
		public function get_data($constraint = '', $limit = '', $order_by = ''){
			if (empty($this-&gt;__table_name)) $this-&gt;throw_error(__METHOD__, __LINE__, 'Table missing.');

			$this-&gt;__sql = &quot;select * from {$this-&gt;__table_name}&quot; . (!empty($constraint)? &quot; where {$constraint}&quot; : '') . (!empty($order_by)? &quot; order by {$this-&gt;escape($order_by)}&quot; : '') . (!empty($limit)? &quot; limit {$this-&gt;escape($limit)}&quot; : '');
			$this-&gt;__result = $this-&gt;__db_handle-&gt;query($this-&gt;__sql);
			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ar_results = array();
			while($obj = $this-&gt;__result-&gt;fetch_object()){
				$ar_results[] = $obj;
			}

			if (is_array($ar_results)){
				return $ar_results;
			}else{
				return false;
			}
		}

		/**
		 * Runs a query and returns results in an array of objects
		 *
		 * @param string $query
		 * @return array
		 */
		public function get_query_data($query){
			if (empty($query)) $this-&gt;throw_error(__METHOD__, __LINE__, &quot;Query missing.&quot;);

			$this-&gt;__sql = $query;
			$this-&gt;__result = $this-&gt;__db_handle-&gt;query($this-&gt;__sql);
			if(!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ar_results = array();
			while ($obj = $this-&gt;__result-&gt;fetch_object()){
				$ar_results[] = $obj;
			}

			if (is_array($ar_results)){
				return $ar_results;
			}else{
				return false;
			}
		}

		/**
		 * Escapes special characters in a string for use in a SQL statement
		 *
		 * @param string $string
		 * @return string
		 */
		public function escape($string){
			return $this-&gt;__db_handle-&gt;real_escape_string($string);
		}

		/**
		 * Alias of function escape
		 *
		 * @param mixed $mixed_var
		 * @return string
		 */
		public function escape_str($mixed_var){
			return $this-&gt;escape($mixed_var);
		}

		/**
		 * Hanldes integers properly for db insertion
		 * Helps prevent injections by converting the mixed var to an int and then attempt to escape it (sanity check)
		 *
		 * @param mixed $mixed_var
		 * @return mixed
		 */
		public function escape_int($mixed_var){
			return $this-&gt;__db_handle-&gt;real_escape_string(intval($mixed_var));
		}

		/**
		 * Gets the sql statement that was executed
		 *
		 * @return string
		 */
		public function get_sql(){
			return $this-&gt;__sql;
		}

		/**
		 * Returns the auto generated id used in the last query
		 *
		 * @return int
		 */
		public function get_inserted_id(){
			return mysqli_insert_id($this-&gt;__db_handle);
		}

		/**
		 * Gets the number of rows in a result
		 *
		 * @return int
		 */
		public function get_num_rows(){
			return $this-&gt;__result-&gt;num_rows();
		}

		/**
		 * Gets the number of affected rows in a previous MySQL operation
		 * Returns an integer greater than zero which indicated the number of rows affected or retrieved.
		 * Zero indicates that no records where updated for an UPDATE statement,
		 * no rows matched the WHERE clause in the query or that no query has yet been executed.
		 * -1 indicates that the query returned an error.
		 *
		 * @return int
		 */
		public function get_affected_rows(){
			return $this-&gt;__db_handle-&gt;affected_rows;
		}

		/**
		 * Returns a string providing information about the last query executed.
		 * ex. Records:100 Duplicates:0 Warnings:0 etc.
		 *
		 * @return string
		 */
		public function get_query_info(){
			return $this-&gt;__db_handle-&gt;info;
		}

		private function connect(){
			$this-&gt;__db_handle = new mysqli($this-&gt;__db_host, $this-&gt;__db_username, $this-&gt;__db_password, $this-&gt;__db_name);
			if (mysqli_connect_errno()){
				$this-&gt;throw_error(__METHOD__, __LINE__, mysqli_connect_error);
			}
		}

		private function get_single_result(){
			$this-&gt;__result = $this-&gt;__db_handle-&gt;query($this-&gt;__sql);
			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__);
			}

			$ob_record = $this-&gt;__result-&gt;fetch_object();
			if (is_object($ob_record)){
				foreach($ob_record as $key =&gt; $value){
					$this-&gt;{$key} = $value;
				}
				return $this;
			}else{
				return false;
			}
		}

		private function get_table_fields(){
			$this-&gt;__sql = &quot;select * from {$this-&gt;escape($this-&gt;__table_name)} limit 1&quot;;

			$this-&gt;__result = $this-&gt;__db_handle-&gt;query($this-&gt;__sql);
			if (!$this-&gt;__result){
				$this-&gt;throw_error(__METHOD__, __LINE__,'Could not fetch table fields.');
			}

			$ar_field_info = $this-&gt;__result-&gt;fetch_fields();
			if (is_array($ar_field_info)){
				foreach ($ar_field_info as $val){
					$ar_fields[$val-&gt;name]-&gt;name = $val-&gt;name;
					$ar_fields[$val-&gt;name]-&gt;orgname = $val-&gt;orgname;
					$ar_fields[$val-&gt;name]-&gt;table = $val-&gt;table;
					$ar_fields[$val-&gt;name]-&gt;orgtable = $val-&gt;orgtable;
					$ar_fields[$val-&gt;name]-&gt;def = $val-&gt;def;
					$ar_fields[$val-&gt;name]-&gt;max_length = $val-&gt;max_length;
					$ar_fields[$val-&gt;name]-&gt;length = $val-&gt;length;
					$ar_fields[$val-&gt;name]-&gt;charsetnr = $val-&gt;charsetnr;
					$ar_fields[$val-&gt;name]-&gt;flags = $val-&gt;flags;
					$ar_fields[$val-&gt;name]-&gt;type = $this-&gt;__ar_field_types[$val-&gt;type];
					$ar_fields[$val-&gt;name]-&gt;decimals = $val-&gt;decimals;
				}
				return $ar_fields;
			}else{
				$this-&gt;throw_error(__METHOD__, __LINE__, &quot;No columns found for table {$this-&gt;__table_name}.&quot;);
			}
		}

		private function throw_error($function_name, $line_number, $error_msg = ''){
			die('&lt;font style=&quot;color: red; font-weight: bold;&quot;&gt;-- Error --&lt;/font&gt;&lt;br /&gt;' . $function_name . ' at line ' . $line_number . '&lt;br /&gt;MySQLi Error: ' . $this-&gt;__db_handle-&gt;error . (!empty($error_msg)? &quot;&lt;br /&gt;Message: $error_msg&quot; : &quot;&quot;));
		}

	}
?&gt;
</pre>
<p>All code is Copyright 2009 by Ashwin Surajbali (http://www.redinkdesign.net).</p>
<p>This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation.</p>
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.</p>
<p>You can view a copy of the GNU General Public Licsense at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.</p>
]]></content:encoded>
			<wfw:commentRss>http://redinkdesign.net/programming/php/php-mysqli-table-to-object-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Mime Type&#8217;s Array</title>
		<link>http://redinkdesign.net/programming/php/php-mime-types-array/</link>
		<comments>http://redinkdesign.net/programming/php/php-mime-types-array/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 14:50:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Just a simple php mime type array

<code>
$mimes = array(
      'hqx'   =&#62;  'application/mac-binhex40',
      'cpt'   =&#62;  'application/mac-compactpro',
      'doc'   =&#62;  'application/msword',
      'bin'   =&#62;  'application/macbinary',
      'dms'   =&#62;  'application/octet-stream',
      'lha'   =&#62;  'application/octet-stream',
      'lzh'   =&#62;  'application/octet-stream',
      'exe'   =&#62;  'application/octet-stream',
      'class' =&#62;  'application/octet-stream',
      'psd'   =&#62;  'application/octet-stream',
      'so'    =&#62;  'application/octet-stream',
]]></description>
			<content:encoded><![CDATA[<p>Just a simple php mime type array</p>
<pre class="brush: php;">
$mimes = array(
      'hqx'   =&gt;  'application/mac-binhex40',
      'cpt'   =&gt;  'application/mac-compactpro',
      'doc'   =&gt;  'application/msword',
      'bin'   =&gt;  'application/macbinary',
      'dms'   =&gt;  'application/octet-stream',
      'lha'   =&gt;  'application/octet-stream',
      'lzh'   =&gt;  'application/octet-stream',
      'exe'   =&gt;  'application/octet-stream',
      'class' =&gt;  'application/octet-stream',
      'psd'   =&gt;  'application/octet-stream',
      'so'    =&gt;  'application/octet-stream',
      'sea'   =&gt;  'application/octet-stream',
      'dll'   =&gt;  'application/octet-stream',
      'oda'   =&gt;  'application/oda',
      'pdf'   =&gt;  'application/pdf',
      'ai'    =&gt;  'application/postscript',
      'eps'   =&gt;  'application/postscript',
      'ps'    =&gt;  'application/postscript',
      'smi'   =&gt;  'application/smil',
      'smil'  =&gt;  'application/smil',
      'mif'   =&gt;  'application/vnd.mif',
      'xls'   =&gt;  'application/vnd.ms-excel',
      'ppt'   =&gt;  'application/vnd.ms-powerpoint',
      'wbxml' =&gt;  'application/vnd.wap.wbxml',
      'wmlc'  =&gt;  'application/vnd.wap.wmlc',
      'dcr'   =&gt;  'application/x-director',
      'dir'   =&gt;  'application/x-director',
      'dxr'   =&gt;  'application/x-director',
      'dvi'   =&gt;  'application/x-dvi',
      'gtar'  =&gt;  'application/x-gtar',
      'php'   =&gt;  'application/x-httpd-php',
      'php4'  =&gt;  'application/x-httpd-php',
      'php3'  =&gt;  'application/x-httpd-php',
      'phtml' =&gt;  'application/x-httpd-php',
      'phps'  =&gt;  'application/x-httpd-php-source',
      'js'    =&gt;  'application/x-javascript',
      'swf'   =&gt;  'application/x-shockwave-flash',
      'sit'   =&gt;  'application/x-stuffit',
      'tar'   =&gt;  'application/x-tar',
      'tgz'   =&gt;  'application/x-tar',
      'xhtml' =&gt;  'application/xhtml+xml',
      'xht'   =&gt;  'application/xhtml+xml',
      'zip'   =&gt;  'application/zip',
      'mid'   =&gt;  'audio/midi',
      'midi'  =&gt;  'audio/midi',
      'mpga'  =&gt;  'audio/mpeg',
      'mp2'   =&gt;  'audio/mpeg',
      'mp3'   =&gt;  'audio/mpeg',
      'aif'   =&gt;  'audio/x-aiff',
      'aiff'  =&gt;  'audio/x-aiff',
      'aifc'  =&gt;  'audio/x-aiff',
      'ram'   =&gt;  'audio/x-pn-realaudio',
      'rm'    =&gt;  'audio/x-pn-realaudio',
      'rpm'   =&gt;  'audio/x-pn-realaudio-plugin',
      'ra'    =&gt;  'audio/x-realaudio',
      'rv'    =&gt;  'video/vnd.rn-realvideo',
      'wav'   =&gt;  'audio/x-wav',
      'bmp'   =&gt;  'image/bmp',
      'gif'   =&gt;  'image/gif',
      'jpeg'  =&gt;  'image/jpeg',
      'jpg'   =&gt;  'image/jpeg',
      'jpe'   =&gt;  'image/jpeg',
      'png'   =&gt;  'image/png',
      'tiff'  =&gt;  'image/tiff',
      'tif'   =&gt;  'image/tiff',
      'css'   =&gt;  'text/css',
      'html'  =&gt;  'text/html',
      'htm'   =&gt;  'text/html',
      'shtml' =&gt;  'text/html',
      'txt'   =&gt;  'text/plain',
      'text'  =&gt;  'text/plain',
      'log'   =&gt;  'text/plain',
      'rtx'   =&gt;  'text/richtext',
      'rtf'   =&gt;  'text/rtf',
      'xml'   =&gt;  'text/xml',
      'xsl'   =&gt;  'text/xml',
      'mpeg'  =&gt;  'video/mpeg',
      'mpg'   =&gt;  'video/mpeg',
      'mpe'   =&gt;  'video/mpeg',
      'qt'    =&gt;  'video/quicktime',
      'mov'   =&gt;  'video/quicktime',
      'avi'   =&gt;  'video/x-msvideo',
      'movie' =&gt;  'video/x-sgi-movie',
      'doc'   =&gt;  'application/msword',
      'word'  =&gt;  'application/msword',
      'xl'    =&gt;  'application/excel',
      'eml'   =&gt;  'message/rfc822'
    );
</pre>
]]></content:encoded>
			<wfw:commentRss>http://redinkdesign.net/programming/php/php-mime-types-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Country Array</title>
		<link>http://redinkdesign.net/programming/php/php-country-array/</link>
		<comments>http://redinkdesign.net/programming/php/php-country-array/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 11:39:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This array can be used to build out a Country drop down list.

<code>
'AFGHANISTAN',
		'AL'=&#62;'ALBANIA',
		'DZ'=&#62;'ALGERIA',
		'AS'=&#62;'AMERICAN SAMOA',
		'AD'=&#62;'ANDORRA',
		'AO'=&#62;'ANGOLA',
		'AI'=&#62;'ANGUILLA',
		'AQ'=&#62;'ANTARCTICA',
		'AG'=&#62;'ANTIGUA AND BARBUDA',
		'AR'=&#62;'ARGENTINA',
		'AM'=&#62;'ARMENIA',
		'AW'=&#62;'ARUBA',
		'AU'=&#62;'AUSTRALIA',
		'AT'=&#62;'AUSTRIA',
		'AZ'=&#62;'AZERBAIJAN',
		'BS'=&#62;'BAHAMAS',
		'BH'=&#62;'BAHRAIN',
		'BD'=&#62;'BANGLADESH',
		'BB'=&#62;'BARBADOS',
		'BY'=&#62;'BELARUS',
		'BE'=&#62;'BELGIUM',
		'BZ'=&#62;'BELIZE',
]]></description>
			<content:encoded><![CDATA[<p>This array can be used to build out a Country drop down list.</p>
<pre class="brush: php;">
&lt;?php
	$ar_countries = array(
		'AF'=&gt;'AFGHANISTAN',
		'AL'=&gt;'ALBANIA',
		'DZ'=&gt;'ALGERIA',
		'AS'=&gt;'AMERICAN SAMOA',
		'AD'=&gt;'ANDORRA',
		'AO'=&gt;'ANGOLA',
		'AI'=&gt;'ANGUILLA',
		'AQ'=&gt;'ANTARCTICA',
		'AG'=&gt;'ANTIGUA AND BARBUDA',
		'AR'=&gt;'ARGENTINA',
		'AM'=&gt;'ARMENIA',
		'AW'=&gt;'ARUBA',
		'AU'=&gt;'AUSTRALIA',
		'AT'=&gt;'AUSTRIA',
		'AZ'=&gt;'AZERBAIJAN',
		'BS'=&gt;'BAHAMAS',
		'BH'=&gt;'BAHRAIN',
		'BD'=&gt;'BANGLADESH',
		'BB'=&gt;'BARBADOS',
		'BY'=&gt;'BELARUS',
		'BE'=&gt;'BELGIUM',
		'BZ'=&gt;'BELIZE',
		'BJ'=&gt;'BENIN',
		'BM'=&gt;'BERMUDA',
		'BT'=&gt;'BHUTAN',
		'BO'=&gt;'BOLIVIA',
		'BA'=&gt;'BOSNIA AND HERZEGOVINA',
		'BW'=&gt;'BOTSWANA',
		'BV'=&gt;'BOUVET ISLAND',
		'BR'=&gt;'BRAZIL',
		'IO'=&gt;'BRITISH INDIAN OCEAN TERRITORY',
		'BN'=&gt;'BRUNEI DARUSSALAM',
		'BG'=&gt;'BULGARIA',
		'BF'=&gt;'BURKINA FASO',
		'BI'=&gt;'BURUNDI',
		'KH'=&gt;'CAMBODIA',
		'CM'=&gt;'CAMEROON',
		'CA'=&gt;'CANADA',
		'CV'=&gt;'CAPE VERDE',
		'KY'=&gt;'CAYMAN ISLANDS',
		'CF'=&gt;'CENTRAL AFRICAN REPUBLIC',
		'TD'=&gt;'CHAD',
		'CL'=&gt;'CHILE',
		'CN'=&gt;'CHINA',
		'CX'=&gt;'CHRISTMAS ISLAND',
		'CC'=&gt;'COCOS (KEELING) ISLANDS',
		'CO'=&gt;'COLOMBIA',
		'KM'=&gt;'COMOROS',
		'CG'=&gt;'CONGO',
		'CD'=&gt;'CONGO, THE DEMOCRATIC REPUBLIC OF THE',
		'CK'=&gt;'COOK ISLANDS',
		'CR'=&gt;'COSTA RICA',
		'CI'=&gt;'COTE D IVOIRE',
		'HR'=&gt;'CROATIA',
		'CU'=&gt;'CUBA',
		'CY'=&gt;'CYPRUS',
		'CZ'=&gt;'CZECH REPUBLIC',
		'DK'=&gt;'DENMARK',
		'DJ'=&gt;'DJIBOUTI',
		'DM'=&gt;'DOMINICA',
		'DO'=&gt;'DOMINICAN REPUBLIC',
		'TP'=&gt;'EAST TIMOR',
		'EC'=&gt;'ECUADOR',
		'EG'=&gt;'EGYPT',
		'SV'=&gt;'EL SALVADOR',
		'GQ'=&gt;'EQUATORIAL GUINEA',
		'ER'=&gt;'ERITREA',
		'EE'=&gt;'ESTONIA',
		'ET'=&gt;'ETHIOPIA',
		'FK'=&gt;'FALKLAND ISLANDS (MALVINAS)',
		'FO'=&gt;'FAROE ISLANDS',
		'FJ'=&gt;'FIJI',
		'FI'=&gt;'FINLAND',
		'FR'=&gt;'FRANCE',
		'GF'=&gt;'FRENCH GUIANA',
		'PF'=&gt;'FRENCH POLYNESIA',
		'TF'=&gt;'FRENCH SOUTHERN TERRITORIES',
		'GA'=&gt;'GABON',
		'GM'=&gt;'GAMBIA',
		'GE'=&gt;'GEORGIA',
		'DE'=&gt;'GERMANY',
		'GH'=&gt;'GHANA',
		'GI'=&gt;'GIBRALTAR',
		'GR'=&gt;'GREECE',
		'GL'=&gt;'GREENLAND',
		'GD'=&gt;'GRENADA',
		'GP'=&gt;'GUADELOUPE',
		'GU'=&gt;'GUAM',
		'GT'=&gt;'GUATEMALA',
		'GN'=&gt;'GUINEA',
		'GW'=&gt;'GUINEA-BISSAU',
		'GY'=&gt;'GUYANA',
		'HT'=&gt;'HAITI',
		'HM'=&gt;'HEARD ISLAND AND MCDONALD ISLANDS',
		'VA'=&gt;'HOLY SEE (VATICAN CITY STATE)',
		'HN'=&gt;'HONDURAS',
		'HK'=&gt;'HONG KONG',
		'HU'=&gt;'HUNGARY',
		'IS'=&gt;'ICELAND',
		'IN'=&gt;'INDIA',
		'ID'=&gt;'INDONESIA',
		'IR'=&gt;'IRAN, ISLAMIC REPUBLIC OF',
		'IQ'=&gt;'IRAQ',
		'IE'=&gt;'IRELAND',
		'IL'=&gt;'ISRAEL',
		'IT'=&gt;'ITALY',
		'JM'=&gt;'JAMAICA',
		'JP'=&gt;'JAPAN',
		'JO'=&gt;'JORDAN',
		'KZ'=&gt;'KAZAKSTAN',
		'KE'=&gt;'KENYA',
		'KI'=&gt;'KIRIBATI',
		'KP'=&gt;'KOREA DEMOCRATIC PEOPLES REPUBLIC OF',
		'KR'=&gt;'KOREA REPUBLIC OF',
		'KW'=&gt;'KUWAIT',
		'KG'=&gt;'KYRGYZSTAN',
		'LA'=&gt;'LAO PEOPLES DEMOCRATIC REPUBLIC',
		'LV'=&gt;'LATVIA',
		'LB'=&gt;'LEBANON',
		'LS'=&gt;'LESOTHO',
		'LR'=&gt;'LIBERIA',
		'LY'=&gt;'LIBYAN ARAB JAMAHIRIYA',
		'LI'=&gt;'LIECHTENSTEIN',
		'LT'=&gt;'LITHUANIA',
		'LU'=&gt;'LUXEMBOURG',
		'MO'=&gt;'MACAU',
		'MK'=&gt;'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF',
		'MG'=&gt;'MADAGASCAR',
		'MW'=&gt;'MALAWI',
		'MY'=&gt;'MALAYSIA',
		'MV'=&gt;'MALDIVES',
		'ML'=&gt;'MALI',
		'MT'=&gt;'MALTA',
		'MH'=&gt;'MARSHALL ISLANDS',
		'MQ'=&gt;'MARTINIQUE',
		'MR'=&gt;'MAURITANIA',
		'MU'=&gt;'MAURITIUS',
		'YT'=&gt;'MAYOTTE',
		'MX'=&gt;'MEXICO',
		'FM'=&gt;'MICRONESIA, FEDERATED STATES OF',
		'MD'=&gt;'MOLDOVA, REPUBLIC OF',
		'MC'=&gt;'MONACO',
		'MN'=&gt;'MONGOLIA',
		'MS'=&gt;'MONTSERRAT',
		'MA'=&gt;'MOROCCO',
		'MZ'=&gt;'MOZAMBIQUE',
		'MM'=&gt;'MYANMAR',
		'NA'=&gt;'NAMIBIA',
		'NR'=&gt;'NAURU',
		'NP'=&gt;'NEPAL',
		'NL'=&gt;'NETHERLANDS',
		'AN'=&gt;'NETHERLANDS ANTILLES',
		'NC'=&gt;'NEW CALEDONIA',
		'NZ'=&gt;'NEW ZEALAND',
		'NI'=&gt;'NICARAGUA',
		'NE'=&gt;'NIGER',
		'NG'=&gt;'NIGERIA',
		'NU'=&gt;'NIUE',
		'NF'=&gt;'NORFOLK ISLAND',
		'MP'=&gt;'NORTHERN MARIANA ISLANDS',
		'NO'=&gt;'NORWAY',
		'OM'=&gt;'OMAN',
		'PK'=&gt;'PAKISTAN',
		'PW'=&gt;'PALAU',
		'PS'=&gt;'PALESTINIAN TERRITORY, OCCUPIED',
		'PA'=&gt;'PANAMA',
		'PG'=&gt;'PAPUA NEW GUINEA',
		'PY'=&gt;'PARAGUAY',
		'PE'=&gt;'PERU',
		'PH'=&gt;'PHILIPPINES',
		'PN'=&gt;'PITCAIRN',
		'PL'=&gt;'POLAND',
		'PT'=&gt;'PORTUGAL',
		'PR'=&gt;'PUERTO RICO',
		'QA'=&gt;'QATAR',
		'RE'=&gt;'REUNION',
		'RO'=&gt;'ROMANIA',
		'RU'=&gt;'RUSSIAN FEDERATION',
		'RW'=&gt;'RWANDA',
		'SH'=&gt;'SAINT HELENA',
		'KN'=&gt;'SAINT KITTS AND NEVIS',
		'LC'=&gt;'SAINT LUCIA',
		'PM'=&gt;'SAINT PIERRE AND MIQUELON',
		'VC'=&gt;'SAINT VINCENT AND THE GRENADINES',
		'WS'=&gt;'SAMOA',
		'SM'=&gt;'SAN MARINO',
		'ST'=&gt;'SAO TOME AND PRINCIPE',
		'SA'=&gt;'SAUDI ARABIA',
		'SN'=&gt;'SENEGAL',
		'SC'=&gt;'SEYCHELLES',
		'SL'=&gt;'SIERRA LEONE',
		'SG'=&gt;'SINGAPORE',
		'SK'=&gt;'SLOVAKIA',
		'SI'=&gt;'SLOVENIA',
		'SB'=&gt;'SOLOMON ISLANDS',
		'SO'=&gt;'SOMALIA',
		'ZA'=&gt;'SOUTH AFRICA',
		'GS'=&gt;'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS',
		'ES'=&gt;'SPAIN',
		'LK'=&gt;'SRI LANKA',
		'SD'=&gt;'SUDAN',
		'SR'=&gt;'SURINAME',
		'SJ'=&gt;'SVALBARD AND JAN MAYEN',
		'SZ'=&gt;'SWAZILAND',
		'SE'=&gt;'SWEDEN',
		'CH'=&gt;'SWITZERLAND',
		'SY'=&gt;'SYRIAN ARAB REPUBLIC',
		'TW'=&gt;'TAIWAN, PROVINCE OF CHINA',
		'TJ'=&gt;'TAJIKISTAN',
		'TZ'=&gt;'TANZANIA, UNITED REPUBLIC OF',
		'TH'=&gt;'THAILAND',
		'TG'=&gt;'TOGO',
		'TK'=&gt;'TOKELAU',
		'TO'=&gt;'TONGA',
		'TT'=&gt;'TRINIDAD AND TOBAGO',
		'TN'=&gt;'TUNISIA',
		'TR'=&gt;'TURKEY',
		'TM'=&gt;'TURKMENISTAN',
		'TC'=&gt;'TURKS AND CAICOS ISLANDS',
		'TV'=&gt;'TUVALU',
		'UG'=&gt;'UGANDA',
		'UA'=&gt;'UKRAINE',
		'AE'=&gt;'UNITED ARAB EMIRATES',
		'GB'=&gt;'UNITED KINGDOM',
		'US'=&gt;'UNITED STATES',
		'UM'=&gt;'UNITED STATES MINOR OUTLYING ISLANDS',
		'UY'=&gt;'URUGUAY',
		'UZ'=&gt;'UZBEKISTAN',
		'VU'=&gt;'VANUATU',
		'VE'=&gt;'VENEZUELA',
		'VN'=&gt;'VIET NAM',
		'VG'=&gt;'VIRGIN ISLANDS, BRITISH',
		'VI'=&gt;'VIRGIN ISLANDS, U.S.',
		'WF'=&gt;'WALLIS AND FUTUNA',
		'EH'=&gt;'WESTERN SAHARA',
		'YE'=&gt;'YEMEN',
		'YU'=&gt;'YUGOSLAVIA',
		'ZM'=&gt;'ZAMBIA',
		'ZW'=&gt;'ZIMBABWE'
	);
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://redinkdesign.net/programming/php/php-country-array/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Google Weather API Class</title>
		<link>http://redinkdesign.net/programming/google-weather-api-class/</link>
		<comments>http://redinkdesign.net/programming/google-weather-api-class/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 16:13:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Pull weather data from Google's weather API (http://www.google.com/ig/api?weather=10027). This class grabs the raw data (xml) and creates a nicely formatted associative array containing the weather information. 

Example:
<code>
$w = new googleWeather();
$w-&#62;enable_cache = 1;
$w-&#62;cache_path = '/var/www/mysite.com/cache';
$ar_data = $w-&#62;get_weather_data(10027);
print_r($ar_data);
echo $ar_data['forecast'][0]['day_of_week'];
</code>


Source:
<code>&#60;?php

	/**
	 * Grabs weather data from Google.com&#39;s weather API and return a nicely formatted array
	 *
]]></description>
			<content:encoded><![CDATA[<p>Most updated code is now on Github.</p>
<p><a href="https://github.com/redinkdesign/Google-Weather-API">https://github.com/redinkdesign/Google-Weather-API</a></p>
]]></content:encoded>
			<wfw:commentRss>http://redinkdesign.net/programming/google-weather-api-class/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

