<?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"
	>

<channel>
	<title>The Q</title>
	<atom:link href="http://www.mc2design.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mc2design.com/blog</link>
	<description>Web development and marketing from the squares at MC² Design Group</description>
	<pubDate>Fri, 02 May 2008 16:25:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Detecting if user is logged in with Miva Store Morph</title>
		<link>http://www.mc2design.com/blog/detecting-if-user-is-logged-in-with-miva-store-morph</link>
		<comments>http://www.mc2design.com/blog/detecting-if-user-is-logged-in-with-miva-store-morph#comments</comments>
		<pubDate>Wed, 30 Apr 2008 23:31:33 +0000</pubDate>
		<dc:creator>Luke Visinoni</dc:creator>
		
		<category><![CDATA[Miva]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/?p=133</guid>
		<description><![CDATA[As I was working on a Miva Merchant store today, I needed to show the user a link, but only if they were currently logged in. I know I have done this before, but I couldn&#8217;t find the code for the life of me. So I went to trusty ol&#8217; Google and typed in &#8220;Miva [...]]]></description>
			<content:encoded><![CDATA[<p>As I was working on a Miva Merchant store today, I needed to show the user a link, but only if they were currently logged in. I know I have done this before, but I couldn&#8217;t find the code for the life of me. So I went to trusty ol&#8217; Google and typed in &#8220;Miva Merchant detect if user logged in&#8221; and several other terms only to come up with nothing. So I dug through several other Merchant sites to find the code. I finally found it and have decided to post it here in case somebody else has the same problem.</p>
<p class="update">UPDATE: Apparently you need to check that g.Basket:CUST_ID is not equal to zero. At first my solution only checked that it wasn&#8217;t null which was flawed.</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mvt:if</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;NOT ISNULL g.Basket:CUST_ID AND g.Basket:CUST_ID NE 0&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    Welcome back, <span style="color: #ddbb00;">&amp;mvte:global:customer:login;</span>!
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mvt:else<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    Hello anonymous user!
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mvt:if<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/detecting-if-user-is-logged-in-with-miva-store-morph/feed</wfw:commentRss>
		</item>
		<item>
		<title>Zend Framework version 1.5 officially released</title>
		<link>http://www.mc2design.com/blog/zend-framework-version-15-officially-released</link>
		<comments>http://www.mc2design.com/blog/zend-framework-version-15-officially-released#comments</comments>
		<pubDate>Fri, 21 Mar 2008 18:18:00 +0000</pubDate>
		<dc:creator>Luke Visinoni</dc:creator>
		
		<category><![CDATA[Industry News]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/zend-framework-version-15-officially-released</guid>
		<description><![CDATA[The Zend Framework has always been my favorite PHP framework. The thing I love about this framework is that its components are loosely coupled. That is to say that its components have well-defined, and well-thought out dependencies. If you don&#8217;t like certain components, you don&#8217;t have to use them. Other frameworks boast this kind of [...]]]></description>
			<content:encoded><![CDATA[<p>The Zend Framework has always been my favorite PHP framework. The thing I love about this framework is that its components are loosely coupled. That is to say that its components have well-defined, and well-thought out dependencies. If you don&#8217;t like certain components, you don&#8217;t have to use them. Other frameworks boast this kind of modularity, but honestly I haven&#8217;t seen any that really back it up. For our last two or three PHP projects, we gave CakePHP a try. At first I was really happy with cake because of how quickly I was able to wire frame an application, but the more I use it the more I realize that the components in cake are far too coupled and there is just too damn much &#8220;auto-magic&#8221; going on in cake. I really prefer explicit to implicit code.</p>
<p>The reason we decided to leave Zend and go to CakePHP was because it lacked two main components that made it very difficult to wire frame applications quickly and easily. Those components are a <a href="http://framework.zend.com/manual/en/zend.layout.html">layout system</a>, and a <a href="http://framework.zend.com/manual/en/zend.form.html">form manager</a>. I am happy to announce that Zend has tackled both of these problems in this release, and has actually done a decent job on them. Neither of them are 100% yet (at least not in my opinion), but both are very usable and helpful at the very least. Go grab a copy of <a href="http://framework.zend.com/download">the new release</a> and give it a go. I think you&#8217;ll be quite happy with it!</p>
<p>For a full list of the new features, check out <a href="http://devzone.zend.com/article/3270-Zend-Technologies-Releases-Zend-Framework-1.5">the official release page on zend developer zone</a>.0</p>
<p><strong>UPDATE!</strong> - Zend Developer Zone has published <a href="http://www.zend.com/webinar/Framework/webinar-ZF-Layout-20080319.flv">a webinar on Zend_View and Zend_Layout by Ralph Schindler</a>. Go check it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/zend-framework-version-15-officially-released/feed</wfw:commentRss>
		</item>
		<item>
		<title>Butte Business Resources</title>
		<link>http://www.mc2design.com/blog/butte-business-resources</link>
		<comments>http://www.mc2design.com/blog/butte-business-resources#comments</comments>
		<pubDate>Thu, 20 Mar 2008 18:36:01 +0000</pubDate>
		<dc:creator>Michael Coogan</dc:creator>
		
		<category><![CDATA[Client News]]></category>

		<category><![CDATA[Press]]></category>

		<category><![CDATA[Site Showcase]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/butte-business-resources</guid>
		<description><![CDATA[
Website: www.buttebusinessresources.com
Formula:

Content Management System
Clean/verbose urls
Valid XHTML 1.0 Transitional
CSS2.1
Word Press integration

Debut: March, 2008
Chabin Concepts and MC2 Design are proud to announce the release of Butte County&#8217;s new regional economic development and business resource site: ButteBusinessResources.com. Designed and developed by MC2, the site is geared to be a central location for businesses in Butte County to find [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.buttebusinessresources.com/" title="Butte Business Resources" rel="external" class="bordered"><img src="http://www.mc2design.com/blog/wp-content/uploads/2008/03/buttebusiness-preview.jpg" alt="Butte Business Resources" align="right" /></a></p>
<p><strong>Website:</strong> <a href="http://www.buttebusinessresources.com/" rel="external">www.buttebusinessresources.com</a><br />
<strong>Formula:</strong></p>
<ul>
<li>Content Management System</li>
<li><a href="http://en.wikipedia.org/wiki/URL#Clean_URLs" rel="external">Clean/verbose urls</a></li>
<li>Valid <a href="http://en.wikipedia.org/wiki/XHTML#XHTML_1.0" rel="external">XHTML 1.0 Transitional</a></li>
<li><a href="http://en.wikipedia.org/wiki/CSS2.1" rel="external">CSS2.1</a></li>
<li>Word Press integration</li>
</ul>
<p><strong>Debut:</strong> March, 2008</p>
<p><a href="http://www.chabinconcepts.com">Chabin Concepts</a> and MC2 Design are proud to announce the release of Butte County&#8217;s new regional economic development and business resource site: <a href="http://www.buttebusinessresources.com" rel="external">ButteBusinessResources.com</a>. Designed and developed by MC2, the site is geared to be a central location for businesses in Butte County to find resources in business development, funding, marketing, business expansion, human resources, and consulting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/butte-business-resources/feed</wfw:commentRss>
		</item>
		<item>
		<title>PHP CSV Utilities v0.2 released - now able to detect the format of a csv file</title>
		<link>http://www.mc2design.com/blog/php-csv-utilities-v02-has-been-released</link>
		<comments>http://www.mc2design.com/blog/php-csv-utilities-v02-has-been-released#comments</comments>
		<pubDate>Sun, 16 Mar 2008 07:30:52 +0000</pubDate>
		<dc:creator>Luke Visinoni</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[PHP CSV Utilities]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/php-csv-utilities-v02-has-been-released</guid>
		<description><![CDATA[Download PHP CSV Utililties v0.2
Read Documentation for PHP CSV Utilities
I have just wrapped up version 0.2 of our csv library. It includes several new features. The most exciting of which is the new Csv_Sniffer class.

Csv_Sniffer
sniff(string $sample)
Csv_Sniffer&#8217;s sniff method accepts a sample of csv data and attempts to deduce its format. In this library, there is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/php-csv-utils/downloads/list">Download PHP CSV Utililties v0.2</a><br />
<a href="http://code.google.com/p/php-csv-utils/wiki/Documentation">Read Documentation for PHP CSV Utilities</a></p>
<p>I have just wrapped up version 0.2 of <a href="http://www.mc2design.com/blog/php-csv-utilities-a-php-library-similar-to-pythons-standard-csv-module">our csv library</a>. It includes several new features. The most exciting of which is the new Csv_Sniffer class.</p>
<p><span id="more-124"></span></p>
<h3>Csv_Sniffer</h3>
<p><strong>sniff(string $sample)</strong><br />
Csv_Sniffer&#8217;s sniff method accepts a sample of csv data and attempts to deduce its format. In this library, there is a class called Csv_Dialect, which tells Csv_Reader and Csv_Writer the format they should read and write in. If Csv_Sniffer::sniff is successful, it will return a Csv_Dialect object representing the format of the csv file (or at least it&#8217;s best guess). You can then pass this dialect to Csv_Reader and it will know how to read the file. You can also pass it to Csv_Writer if you need to append the file or write one in the same format.</p>

<div class="wp_syntax"><div class="code"><pre class="php">try <span style="color: #66cc66;">&#123;</span>
    <span style="color: #ff0000">$sample</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">implode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #000066;">array_slice</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">file</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'./data/products.csv'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// grab 20 lines</span>
    <span style="color: #ff0000">$sniffer</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Sniffer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff0000">$dialect</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$sniffer</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">sniff</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$sample</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Reader<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'./data/products.csv'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$dialect</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> catch <span style="color: #66cc66;">&#40;</span>Csv_Exception_CannotDetermineDialect <span style="color: #ff0000">$e</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&lt;p&gt;%s&lt;/p&gt;&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$e</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>hasHeader(string $sample)</strong><br />
Csv_Sniffer&#8217;s hasHeader method accepts a sample of csv data and attempts to detect if the file has a header row or not. If so it will return true.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$sample</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">implode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #000066;">array_slice</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">file</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'./data/products.csv'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// grab 20 lines</span>
<span style="color: #ff0000">$sniffer</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Sniffer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$sniffer</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">hasHeader</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$sample</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;The file probably has a header&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;The file probably doesn't have a header&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Csv_Reader_String</h3>
<p>This new class is exactly the same as Csv_Reader, except instead of accepting a filename and reading from a file, it reads directly from a string. This could be useful if for some reason somebody had stored csv data in a database and you were retrieving it from there, or if you needed to collect submitted csv data directly from a web form.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'csv_data'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #ff0000">$data</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'csv_data'</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Reader_String<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$data</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$reader</span> <span style="color: #b1b100;">as</span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// now you could insert it into a database or whatever else you need to do with it</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Csv_Dialect::__construct([array $options])</strong></p>
<p>You may now pass an associative array to Csv_Dialect&#8217;s constructor to override any of it&#8217;s properties. While this doesn&#8217;t actually provide any new features, it definitely is a convenience.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$dialect</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Dialect<span style="color: #66cc66;">&#40;</span><span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'quotechar'</span> <span style="color: #66cc66;">=&gt;</span> <span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'escapechar'</span> <span style="color: #66cc66;">=&gt;</span> <span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'quoting'</span> <span style="color: #66cc66;">=&gt;</span> Csv_Dialect<span style="color: #66cc66;">::</span><span style="color: #006600;">QUOTE_NONNUMERIC</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Reader<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'./data/orders.csv'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$dialect</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<h3>Plans for version 0.3</h3>
<ul>
<li><strong>Csv_Writer will write immediately, rather than when you call close()</strong> - This won&#8217;t change the interface at all, but in the next version, instead of writing to disk when the user calls close(), it will write immediately when writeRow() or writeRows() is called.</li>
<li><strong>Interface changes for Csv_Sniffer</strong> - I don&#8217;t like how you have to pass the same sample data to both sniff() and hasHeader(). I will probably change it to accept $sample in its constructor instead. Another issue I have with it is that if there is a tie between delimiter characters in the sniff method, it just chooses by ascii order. I would like to allow the user to specify an array of characters in order of priority in case of a tie.</li>
<li><strong>A more advanced unit testing interface</strong> - The unit tests I have written are all run at once and since they are reading / writing actual csv files it is beginning to take a while to run them all. I&#8217;m putting together an interface that will allow me to run tests seperately or all together as well as a way to time some operations so that I can speed them up as much as possible.</li>
<li><strong>Csv_Dialect classes</strong> for any and all formats I can dig up (Open Office, Miva Merchant, Google Docs and Spreadsheets, <a href="http://en.wikipedia.org/wiki/Comma-separated_values">standard csv</a>?,  etc.)</li>
<li><strong>Csv_Mapper</strong> - A class that maps keys to columns so that you can access them like $row['first_name'].</li>
<li><strong>Even more documentation</strong> I have written <a href="http://code.google.com/p/php-csv-utils/wiki/Documentation">some documentation</a> on the google code wiki, but I am planning on writing more consistent docs. The ones I have now are all sort of willy-nilly.</li>
<li><strong>Csv_Reader_Zip</strong> - A csv reader that can read zipped files</li>
<li><strong>Character encoding</strong> - This will be the first time I have really had to deal with multiple character encodings, so this may take me a while. I will need to do some research on the subject.</li>
<li><strong>More to come</strong> - I will finish writing about the new features and complete the docs within the next week or so, for I am tired and I&#8217;m going to bed.</li>
</ul>
<p><a href="http://code.google.com/p/php-csv-utils/downloads/list">Download PHP CSV Utililties v0.2</a><br />
<a href="http://code.google.com/p/php-csv-utils/wiki/Documentation">Read Documentation for PHP CSV Utilities</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/php-csv-utilities-v02-has-been-released/feed</wfw:commentRss>
		</item>
		<item>
		<title>Cut down on temporary variables in PHP with Fluidics</title>
		<link>http://www.mc2design.com/blog/cut-down-on-temporary-variables-in-php-with-fluidics</link>
		<comments>http://www.mc2design.com/blog/cut-down-on-temporary-variables-in-php-with-fluidics#comments</comments>
		<pubDate>Sat, 15 Mar 2008 03:43:24 +0000</pubDate>
		<dc:creator>Luke Visinoni</dc:creator>
		
		<category><![CDATA[Industry News]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/cut-down-on-temporary-variables-in-php-with-fluidics</guid>
		<description><![CDATA[Ollie Saunders, a colleague of mine and a regular at the DevNetwork forums has put together a very slick little set of functions he has collectively termed &#8220;PHP Fluidics&#8221;. If there is one thing that really sucks about PHP, it&#8217;s how often you have to use temporary variables to get to methods or array elements [...]]]></description>
			<content:encoded><![CDATA[<p>Ollie Saunders, a colleague of mine and a regular at the <a href="http://www.devnetwork.net">DevNetwork forums</a> has put together a very slick little set of functions he has collectively termed &#8220;PHP Fluidics&#8221;. If there is one thing that really sucks about PHP, it&#8217;s how often you have to use temporary variables to get to methods or array elements you need. Fluidics makes this process (and several others) much easier. We use this library in just about everything we code these days and I&#8217;d like to point out a few reasons why.</p>
<p><span id="more-97"></span></p>
<p>One common example is when you need to instantiate an object and call a method on it. Normally, you&#8217;d have to do something like the following.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$person</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MC2_Person<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">23</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$person</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getFullName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>While this isn&#8217;t all that painful when you only need to do it once, in even a moderate sized project, you&#8217;ll need to do something like this hundreds of times. Now let&#8217;s look at the fluidics way to do this.</p>

<div class="wp_syntax"><div class="code"><pre class="php">with<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MC2_person<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">23</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getFullName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>Another extremely useful function in fluidics is the dindex function. After using python for the last few months I have really grown fond of the built-in dictionary method get(). What it does is allow you to request an index on an array (called a dictionary in python) and if it doesn&#8217;t exist, you can provide a default. In python the syntax is like dict.get(&#8217;key&#8217;, &#8216;defaultval&#8217;). In fluidics it&#8217;s like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$lunch</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'snack'</span> <span style="color: #66cc66;">=&gt;</span> <span style="color: #ff0000;">'cheetos'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'drink'</span> <span style="color: #66cc66;">=&gt;</span> <span style="color: #ff0000;">'mountain dew'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$drink</span> <span style="color: #66cc66;">=</span> dindex<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$lunch</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;drink&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;pepsi&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// returns &quot;mountain dew&quot;</span>
<span style="color: #ff0000">$sandwich</span> <span style="color: #66cc66;">=</span> dindex<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$lunch</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;sandwich&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;ham&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// returns &quot;ham&quot;</span></pre></div></div>

<p>I could sit here and list all the functions that make this little library so useful, but Ollie does a better job of it anyway, so check out his googlecode project. I hope you like it as much as I did. </p>
<p><a href="http://code.google.com/p/fluidics/">Read more about fluidics here.</a><br />
<a href="http://olliesaunders.net/">Ollie Saunders&#8217; Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/cut-down-on-temporary-variables-in-php-with-fluidics/feed</wfw:commentRss>
		</item>
		<item>
		<title>Back to the Future - Miva Merchant Conference 2008</title>
		<link>http://www.mc2design.com/blog/back-future-miva-conference-2008</link>
		<comments>http://www.mc2design.com/blog/back-future-miva-conference-2008#comments</comments>
		<pubDate>Thu, 06 Mar 2008 05:53:07 +0000</pubDate>
		<dc:creator>Luke Visinoni</dc:creator>
		
		<category><![CDATA[Client News]]></category>

		<category><![CDATA[Miva]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/back-future-miva-conference-2008</guid>
		<description><![CDATA[The theme of this year&#8217;s Miva Merchant conference, while somewhat cheesy, couldn&#8217;t have been more appropriate. Less than six months ago, we were seriously considering finding another e-commerce platform. Just to give you an idea of how big of a deal that is, MC2 has been working with Miva Merchant since 1998. For those of [...]]]></description>
			<content:encoded><![CDATA[<p>The theme of <a href="http://smallbusiness.miva.com/conference_2008/">this year&#8217;s Miva Merchant conference</a>, while somewhat cheesy, couldn&#8217;t have been more appropriate. Less than six months ago, we were seriously considering finding another e-commerce platform. Just to give you an idea of how big of a deal that is, MC2 has been working with Miva Merchant since 1998. For those of you who are mathematically challenged, that&#8217;s ten years! In computer years, that is a lifetime.</p>
<p><a href="http://www.mc2design.com/blog/wp-content/uploads/2008/03/digitalcameraphotos-archive.jpg" title="Conference Room" class="thickbox"><img src="http://www.mc2design.com/blog/wp-content/uploads/2008/03/room.jpg" alt="Conference Room Thumbnail" class="bordered" align="right" /></a></p>
<h3>Back&#8230;</h3>
<p>To explain why &#8220;Back to the Future&#8221; was such an appropriate theme for the conference, let me give you some background. For those of you who aren&#8217;t aware, FindWhat.com, a search-marketing focused company, purchased Miva Merchant in 2004. They made a few good moves at first, acquiring MVCool and re-branding it as <a href="http://www.mivacentral.com">MivaCentral</a> as well as releasing Miva Merchant 5, but for the next few years they seemed to basically run Merchant into the ground. They alienated module developers, outsourced support, and almost destroyed the community that made it such a success in the first place.</p>
<h3>&#8230;to the Future</h3>
<p>In August of 2007, it was announced that <a href="http://www.mivamerchant.com/company/press/release.mv?Release_ID=95">Miva Merchant had been purchased</a> from FindWhat.com (now <a href="http://www.miva.com">Miva, Inc</a>) by several of the management team who had worked so hard to make the product a success in the past. Within a month, the new team managed to <a href="http://www.mivamerchant.com/company/press/release.mv?Release_ID=96">bring tech support back in-house</a> and drop-kicked the <a href="http://extranet.miva.com/forums/showthread.php?t=8369" showthread.php?t="8369"">ridiculous outsourced design services</a> that had pissed off the community so much.</p>
<h3>The conference? I&#8217;m getting to it!</h3>
<p>My cohort and I arrived in San Diego Thursday night after a whopping hour on a Southwest flight from Sacramento. After getting our rental car and checking in to the hotel, we headed down to the beach and hung out just long enough for me decide we need to open an <em>MC2 Design, San Diego division</em> and then were off to Thursday night&#8217;s mixer where we were given not only a whole <a href="http://www.websyourway.com/memories/mixer0208/DSC_0164">bag of schwag</a>, but also free beer and a chance to meet the infamous <a href="http://www.websyourway.com/memories/mixer0208/DSC_0210">Baron Bob</a>.</p>
<p><span id="more-109"></span></p>
<p>Basically everything I went to the conference to hear was revealed in Rick Wilson&#8217;s keynote on Friday morning. During the keynote, Rick revealed Merchant 5.5 and I think you&#8217;d be hard pressed to find anybody who attended who wasn&#8217;t completely blown away. I&#8217;d just like to go over a few of the features that were revealed in 5.5.</p>
<ul>
<li><strong>Skins</strong> - Easily one of the coolest new features in 5.5 is the skins system. What it does is allow you to completely change the look and feel of your Merchant store with the click of a button. If you are familiar with Wordpress, Miva&#8217;s skin system is similar. We will be making heavy use of this feature.</li>
<li><strong>Dreamweaver integration</strong> - Dreamweaver integration was promised years ago, but it looks like they finally pulled it off. The way this works, is you export the pages you&#8217;d like to edit and simply open them up in Dreamweaver. From here you can edit Merchant&#8217;s templates as if they were simply html documents. In order for this to work you will need to download a free Dreamweaver extension that will be made available via Merchant&#8217;s website.</li>
<li><strong>Completely re-designed interface</strong> - The new interface is wonderful. The first impression I had of Miva Merchant was not good and I have to say one of the main reasons was the interface looked like it came from 1992.</li>
<li><strong>Built-in SEO features</strong> - In the past it has only been possible to customize Merchant&#8217;s URLs by manually creating a mod_rewrite file. The new version has this built right into the admin interface</li>
<li><strong>No more black boxes</strong> - Every piece of html / smt template code in Merchant 5.5 is editable through the interface.</li>
<li><strong>Full CSS support</strong> - The new version comes with a completely css-based skin and the layout is based on divs instead of tables.</li>
<li><strong>Simple administration mode has been removed</strong> - Simple administration mode was the stupidest feature available and it was on by default. In fact, advanced administration mode is a lot simpler than simple administration mode. It has been completely removed from Merchant 5.5.</li>
<li><strong>One-page checkout</strong> - That&#8217;s right. One page checkout is built-in in Merchant 5.5. It is not manditory, but it&#8217;s available. I can&#8217;t recall if this is a &#8220;coming soon&#8221; feature or if it is already implemented</li>
<li><strong>Configurable error pages</strong> - All error pages in Merchant 5.5 are completely customizeable</li>
<li><strong>Unnecessary whitespace removed</strong> - If you have worked with Merchant before, I&#8217;m sure you are aware of the fifteen or twenty blank lines that are output before any html on every page. While this doesn&#8217;t actually make any difference, it is an annoyance I&#8217;m happy that I no longer have to deal with.</li>
</ul>
<p>What is really impressive about all these features is that they were able to pull them off without breaking a single thing. Merchant will be a streamed update and it will not have any effect (other than the updates) on your extisting store(s).</p>
<p><a href="http://www.mc2design.com/blog/wp-content/uploads/2008/03/digitalcameraphotos-archive030608-302.jpg" title="Michael with Rick Wilson"><img src="http://www.mc2design.com/blog/wp-content/uploads/2008/03/michael-and-rick-thumb.jpg" alt="Michael with Rick Wilson" class="bordered" align="right" /></a></p>
<p>Just to be honest, once I was told they&#8217;d be <a href="http://smallbusiness.miva.com/conference_2008/presentations.html">posting slides online</a>, I stopped taking notes. I know there are other features, but I can&#8217;t be sure if they&#8217;re on the way or if they are included in 5.5. I&#8217;ve told you the best of it anyway. I&#8217;ll post links to the slides when they are available. Also, as soon as Michael gets me the photos took of us at the conference, I&#8217;ll post those as well.</p>
<p>I&#8217;d go into detail about the conference sessions, but honestly they were a little lacking. Fortunately the news of Merchant 5.5 as well as the extremely positive experience I had with the new owners were enough to make up for it. The photo to the right is new Executive Vice President, Rick Wilson with Michael. I missed out on getting my photo taken with them because I was discussing code with the dotComHost guys. There is photo of us with those guys on the way.</p>
<p>One small disappointment is that Merchant 5.5 was not released on the day of the conference as was expected, but this is actually a good thing. The new owners decided they weren&#8217;t going to release the new version until it has been thoroughly beta tested and documented. These are two things past versions really could have done a better job of, so it&#8217;s good to see them learning from their mistakes.</p>
<p>Leslie Nord of <a href="http://www.emediasales.com/" rel="external">eMediaSales</a> has posted tons of <a href="http://www.websyourway.com/memories/MM08">photos of the event</a>, so go check &#8216;em out!</p>
<p>UPDATE: Pamela Hazelton of <a href="http://www.designextend.com">Design Extend</a> has written an article along the same theme as this one, only better. <img src='http://www.mc2design.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <a href="http://www.practicalecommerce.com/blogs/mistakes-that-kill/archives/42">Check it out.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/back-future-miva-conference-2008/feed</wfw:commentRss>
		</item>
		<item>
		<title>Overland Equipment</title>
		<link>http://www.mc2design.com/blog/overland-equipment</link>
		<comments>http://www.mc2design.com/blog/overland-equipment#comments</comments>
		<pubDate>Wed, 05 Mar 2008 20:03:39 +0000</pubDate>
		<dc:creator>Luke Visinoni</dc:creator>
		
		<category><![CDATA[Client News]]></category>

		<category><![CDATA[Press]]></category>

		<category><![CDATA[Site Showcase]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/overland-equipment</guid>
		<description><![CDATA[
Website: www.overlandequipment.com
Formula:

Ecommerce/Miva
Clean/verbose urls
Valid XHTML 1.0 Strict
CSS2.1
Dealer database application

Debut: February, 2008
MC2 Design is please to announce Overland Equipment&#8217;s web site launch for the 2008 product year. We have been fortunate to work with Overland Equipment since 2001, designing and developing their corporate website. Overland Equipment is a designer and manufacturer of quality bags since 1981.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://overlandequipment.com/" title="Overland Equipment" rel="external" class="bordered"><img src="http://www.mc2design.com/blog/wp-content/uploads/2008/03/overland-preview.jpg" alt="Overland Equipment" align="right" /></a></p>
<p><strong>Website:</strong> <a href="http://www.overlandequipment.com/" rel="external">www.overlandequipment.com</a><br />
<strong>Formula:</strong></p>
<ul>
<li>Ecommerce/<a href="http://smallbusiness.miva.com/" rel="external">Miva</a></li>
<li><a href="http://en.wikipedia.org/wiki/URL#Clean_URLs" rel="external">Clean/verbose urls</a></li>
<li>Valid <a href="http://en.wikipedia.org/wiki/XHTML#XHTML_1.0" rel="external">XHTML 1.0 Strict</a></li>
<li><a href="http://en.wikipedia.org/wiki/CSS2.1" rel="external">CSS2.1</a></li>
<li>Dealer database application</li>
</ul>
<p><strong>Debut:</strong> February, 2008</p>
<p>MC2 Design is please to announce Overland Equipment&#8217;s web site launch for the 2008 product year. We have been fortunate to work with Overland Equipment since 2001, designing and developing their corporate website. Overland Equipment is a designer and manufacturer of quality bags since 1981.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/overland-equipment/feed</wfw:commentRss>
		</item>
		<item>
		<title>MC2 Development Team Attends MIVA Conference 2008</title>
		<link>http://www.mc2design.com/blog/mc2-development-team-attends-miva-conference-2008</link>
		<comments>http://www.mc2design.com/blog/mc2-development-team-attends-miva-conference-2008#comments</comments>
		<pubDate>Sun, 02 Mar 2008 18:49:45 +0000</pubDate>
		<dc:creator>Michael Coogan</dc:creator>
		
		<category><![CDATA[Industry News]]></category>

		<category><![CDATA[Miva]]></category>

		<category><![CDATA[Press]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/mc2-development-team-attends-miva-conference-2008</guid>
		<description><![CDATA[MC2 Design&#8217;s development team attended the MIVA Merchant 2008 Conference in San Diego, California, held at the Marina Village Conference Centers on Feb 28,29 and March 1st. MIVA Merchant announced exciting new features with its pending release of version 5.5, which released in Beta March 2nd and is slated for streamed release as an upgrade [...]]]></description>
			<content:encoded><![CDATA[<p>MC2 Design&#8217;s development team attended the MIVA Merchant 2008 Conference in San Diego, California, held at the Marina Village Conference Centers on Feb 28,29 and March 1st. MIVA Merchant announced exciting new features with its pending release of version 5.5, which released in Beta March 2nd and is slated for streamed release as an upgrade from 5.0, early to mid April 2008. MC2 came away from the event very encouraged about the vision and future of Miva Merchant as an enterprise level application. The management team of MIVA Merchant provided a very informative, approachable experience, letting merchants, developers, and designers know that they are here to stay.  For additional information on this conference and version 5.5 see <a href="http://www.mc2design.com/blog/back-future-miva-conference-2008">this article</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/mc2-development-team-attends-miva-conference-2008/feed</wfw:commentRss>
		</item>
		<item>
		<title>Sultan of Solar Power</title>
		<link>http://www.mc2design.com/blog/sultan-of-solar-power</link>
		<comments>http://www.mc2design.com/blog/sultan-of-solar-power#comments</comments>
		<pubDate>Sat, 23 Feb 2008 21:59:21 +0000</pubDate>
		<dc:creator>Michael Coogan</dc:creator>
		
		<category><![CDATA[Client News]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/sultan-of-solar-power</guid>
		<description><![CDATA[MC2 Client and innovator FAFCO makes news and progress with their innovations with Solar power and sustainability. Known as a pioneer in solar industry, this Chico-based company manufactures polymer solar heat exchangers for several products, including a residential water-heating system. Recently featured in the Chico News &#38; Reviews Green Guide click to see the full [...]]]></description>
			<content:encoded><![CDATA[<p>MC2 Client and innovator <a href="http://www.fafco.com" rel="external">FAFCO</a> makes news and progress with their innovations with Solar power and sustainability. Known as a pioneer in solar industry, this Chico-based company manufactures polymer solar heat exchangers for several products, including a residential water-heating system. Recently featured in the Chico News &amp; Reviews Green Guide click to see the <a href="http://www.newsreview.com/chico/Content?oid=613801" rel="external">full article</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/sultan-of-solar-power/feed</wfw:commentRss>
		</item>
		<item>
		<title>PHP CSV Utilities - a PHP library similar to python&#8217;s standard CSV module</title>
		<link>http://www.mc2design.com/blog/php-csv-utilities-a-php-library-similar-to-pythons-standard-csv-module</link>
		<comments>http://www.mc2design.com/blog/php-csv-utilities-a-php-library-similar-to-pythons-standard-csv-module#comments</comments>
		<pubDate>Wed, 20 Feb 2008 07:49:21 +0000</pubDate>
		<dc:creator>Luke Visinoni</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[PHP CSV Utilities]]></category>

		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[csv]]></category>

		<category><![CDATA[csv library]]></category>

		<category><![CDATA[excel]]></category>

		<category><![CDATA[library]]></category>

		<category><![CDATA[oop]]></category>

		<category><![CDATA[parser]]></category>

		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.mc2design.com/blog/php-csv-utilities-a-php-library-similar-to-pythons-standard-csv-module</guid>
		<description><![CDATA[Download PHP Csv Utilities
PHP Csv Utilities Documentation (PhpDocumentor)
Since I began doing web development five years ago, I have been exclusively a PHP developer. Recently though, I have taken quite a liking to python. In fact many times while I&#8217;m writing PHP I find myself thinking, &#8220;It sure would be nice if I could do this [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://code.google.com/p/php-csv-utils/downloads/list" rel="external">Download PHP Csv Utilities</a></strong></p>
<p><strong><a href="http://phpcsvutils.mc2design.com/lib/docs/phpdoc/" rel="external">PHP Csv Utilities Documentation</a></strong> (<a href="http://www.phpdoc.org" rel="external">PhpDocumentor</a>)</p>
<p>Since I began doing web development five years ago, I have been exclusively a PHP developer. Recently though, I have taken quite a liking to python. In fact many times while I&#8217;m writing PHP I find myself thinking, &#8220;It sure would be nice if I could do this the python way&#8221;. It&#8217;s not that I don&#8217;t love PHP, it&#8217;s just that python is such an absolute joy to work with. Many features of PHP feel sort of tacked-on as an afterthought. For instance, many standard features available for object-oriented languages are rudimentary or missing completely. Although to PHP&#8217;s credit, <a href="http://devzone.zend.com/article/1714-Whats-New-in-PHP-5">PHP5 and the new Zend engine 2</a> have improved the situation considerably.</p>
<p>Several of the recent projects I&#8217;ve been working on have required an &#8220;import from / export to CSV&#8221; feature. PHP comes with a few functions for reading and writing csv files right out of the box: <a href="http://us.php.net/fgetcsv">fgetcsv</a> and <a href="http://us.php.net/fputcsv">fputcsv</a>. While these are good functions and they get the job done I find they just aren&#8217;t enough in many cases. It would be nice if PHP had an interface like python&#8217;s csv module. Enter PHP CSV Utilities. The library is still in its infancy and nothing about the interface is concrete yet, but here are some of the things that are already possible with the library:</p>
<p><span id="more-103"></span></p>
<p><strong>Open a csv file and parse it line-by-line:</strong></p>
<p>The simplest possible method of reading a csv file is to create a new Csv_Reader object and loop over it with foreach.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Reader<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/path/to/myfile.csv'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$reader</span> <span style="color: #b1b100;">as</span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// do something.. $row now contains an array of the current row</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>What if the file doesn&#8217;t exist?</strong></p>
<p>Csv_Reader will throw a Csv_Exception_FileNotFound exception if it can&#8217;t open the file you provide</p>

<div class="wp_syntax"><div class="code"><pre class="php">try <span style="color: #66cc66;">&#123;</span>
    <span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Reader<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/path/to/file'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> catch <span style="color: #66cc66;">&#40;</span>Csv_Exception_FileNotFound <span style="color: #ff0000">$e</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">echo</span> <span style="color: #ff0000">$e</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Read the header line and then loop through the rest of the lines</strong></p>
<p>If you know the file you are reading has a header row, simply grab it and then loop through the reader with a while loop (foreach will not work here because it starts at the beginning and loops through everything in the reader).</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Reader<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/path/to/myfile.csv'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$header</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$reader</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getRow</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// grabs first row</span>
<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$row</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$reader</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getRow</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// starts from second row</span>
    <span style="color: #808080; font-style: italic;">// do something</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Read a csv file that was created by Excel</strong></p>
<p>Excel has the ability to save as a csv file instead of its proprietary xls format. The library supports what are called Csv dialects (terminology borrowed from python). Csv dialects simply tell reader and writer objects how to do their job. For instance, Excel only quotes columns if there are special characters in them. Using the standard reader would inproperly parse the output of an Excel csv file. To read an Excel csv file properly, simply provide a Csv_Dialect_Excel object in the constructor.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$dialect</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Dialect_Excel<span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Reader<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/path/to/file'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$dialect</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// now reader will read excel csv file properly (this does not mean xls)</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$reader</span> <span style="color: #b1b100;">as</span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// do something</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>But what if I have an excel file with a different delimiter, like a tab character?</strong></p>
<p>If you need to change any of the options in a dialect, you may either extend it via inheritance, or you may simply change said option at run-time.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$dialect</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Dialect_Excel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$dialect</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">delimiter</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$reader</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">setDialect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$dialect</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$reader</span> <span style="color: #b1b100;">as</span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// do something with $row</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Csv_Dialects represent the format of a csv file</strong> - This means you can read or write just about any type of csv file. As of right now, Csv_Dialect has the following properties (most of which were borrowed from python&#8217;s csv module):</p>
<ul>
<li><strong>delimiter</strong> - The delimiter is the character that seperates column values from eachother in a row</li>
<li><strong>quotechar</strong> - The character used to quote columns</li>
<li><strong>escapechar</strong> - The character used to escape special characters such as the delimiter or the quotechar</li>
<li><strong>lineterminator</strong> - The character used to denote the end of a line</li>
<li><strong>quoting</strong> - This tells the reader which rows in the csv file are quoted, and the writer which columns to quote. Can be any of the following Csv_Dialect constants:
<ul>
<li>Csv_Dialect::QUOTE_MINIMAL - Quotes only items that contain special characters such as the delimiter or quotechar</li>
<li>Csv_Dialect::QUOTE_ALL - Quotes all items regardless of their content</li>
<li>Csv_Dialect::QUOTE_NONNUMERIC - Quotes only items with nonnumeric values</li>
<li>Csv_Dialect::QUOTE_NONE - Quotes no items regardless of their content</li>
</ul>
</li>
<li><strong>doublequote</strong> - Not yet implemented</li>
<li><strong>skipinitialspace</strong> - Not yet implemented</li>
<li><strong>skipblanklines</strong> - Set to true if you would like for the reader to ignore blank lines</li>
</ul>
<p><strong>Rewrite a csv file with Excel formatting (or any other format)</strong></p>
<p>The Csv_Writer object accepts a Csv_Reader object in its writeRows() method, so rewriting a csv file with a new dialect (new delimiter, line-ending, etc) is really simple.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$reader</span> <span style="color: #66cc66;">=</span> Csv_Reader<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/path/to/file.csv'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$writer</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Writer<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/path/to/file.csv'</span><span style="color: #66cc66;">,</span> <span style="color: #000000; font-weight: bold;">new</span> Csv_Dialect_Excel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$writer</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">writeRows</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$reader</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$writer</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// writes csv file but now it's in Excel csv format</span></pre></div></div>

<p>I&#8217;d really like to get an idea of features that would be useful to people other than myself. I&#8217;m also interested in feedback on the interface, and ways I could improve the library. If you&#8217;re interested, download the library and play around with it a bit. When you find something you like or dislike or if you have any kind of input at all, leave a comment below or drop me an email. Enjoy!</p>
<p><strong><a href="http://phpcsvutils.mc2design.com/lib/docs/phpdoc/" rel="external">PHP Csv Utilities Documentation</a> (<a href="http://www.phpdoc.org" rel="external">PhpDocumentor</a>)</strong></p>
<p><a href="http://code.google.com/p/php-csv-utils/downloads/list" rel="external">Download PHP Csv Utilities</a></p>
<p><strong>Plans for version 0.2</strong></p>
<ul>
<li><strong>Csv_Sniffer</strong> - a class that accepts a sample of csv and attempts to deduce its format. It will then return a dialect that fits the csv file as well as attempt to detect whether or not the file has a row of headers.</li>
<li><strong>Csv_Dialect classes</strong> for any and all formats I can dig up (Open Office, Miva Merchant, Google Docs and Spreadsheets, <a href="http://en.wikipedia.org/wiki/Comma-separated_values">standard csv</a>?,  etc.)</li>
<li><strong>An option parameter for Csv_Dialect</strong> - I was considering allowing an array of parameters in Csv_Dialect&#8217;s constructor. This way you could easily put together a dialect like $dialect = new Csv_Dialect(array(&#8217;quotechar&#8217; => &#8220;&#8216;&#8221;, &#8216;escapechar&#8217; => &#8216;&#8221;&#8216;));</li>
<li><strong>More comprehensive unit tests</strong> - Although I made my best effort to stick to test-driven development practices (since learning them properly has been on my priority list for a while), there are still some areas where I could use some more testing.</li>
<li><strong>More documentation</strong> - I&#8217;m going to strive to document every feature of this library. Poor documentation is a pet peeve of <em>everybody</em>.</li>
</ul>
<p><strong>Possible / Eventual Features</strong></p>
<ul>
<li><strong>Csv_Reader_Zip</strong> - A csv reader that can read zipped files</li>
<li><strong>Csv_Reader_String</strong> - A csv reader that accepts a string instead of a file</li>
<li><strong>Character encoding</strong> - This will be the first time I have really had to deal with multiple character encodings, so this may take me a while. I will need to do some research on the subject.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.mc2design.com/blog/php-csv-utilities-a-php-library-similar-to-pythons-standard-csv-module/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
