<?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>Solution Log &#124; Antonio David - NVNCBL &#187; php</title>
	<atom:link href="http://www.nvncbl.com/tagged/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nvncbl.com</link>
	<description>A place to log my programming solutions for future reference</description>
	<lastBuildDate>Sun, 28 Aug 2011 01:20:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Script Double Run / Double Execute Phenomenon</title>
		<link>http://www.nvncbl.com/2009/10/script-double-run-double-execute-phenomenon/</link>
		<comments>http://www.nvncbl.com/2009/10/script-double-run-double-execute-phenomenon/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 20:05:29 +0000</pubDate>
		<dc:creator>Antonio</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[double execute]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[img]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[src]]></category>

		<guid isPermaLink="false">http://www.nvncbl.com/?p=458</guid>
		<description><![CDATA[I had a problem with your PHP code running or executing seemingly twice.  To debug this phenomenon, I put some write-to-file code at the beginning of the script.  Surprisingly, whenever I loaded my script in the browser, the file would be written to twice despite my one page load.
The problem was that The page I [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem with your PHP code running or executing seemingly twice.  To debug this phenomenon, I put some write-to-file code at the beginning of the script.  Surprisingly, whenever I loaded my script in the browser, the file would be written to twice despite my one page load.</p>
<p>The problem was that The page I was developing had an &lt;img&gt; in it with the &#8220;src&#8221; attribute set blank.  When the document was fully loaded, javascript was in place to dynamically assign the &#8220;src&#8221;.  This worked perfectly fine in the pre-server-side-logic stage of development so it was an easy decision to begin debugging server-side logic.</p>
<p>The double execute happens when Firefox sees &lt;img src=&#8221;" /&gt;.  Not knowing what source to assign, it sends a request (the second request) to the current path (again) for the image.  Therein lies the problem.  It&#8217;s interesting to note that Firefox is not to blame, as it&#8217;s following HTML specification.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nvncbl.com/2009/10/script-double-run-double-execute-phenomenon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solution to Excel&#8217;s CSV Output Formats</title>
		<link>http://www.nvncbl.com/2009/08/solution-to-excels-csv-output-formats/</link>
		<comments>http://www.nvncbl.com/2009/08/solution-to-excels-csv-output-formats/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 05:23:17 +0000</pubDate>
		<dc:creator>Antonio</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.nvncbl.com/?p=352</guid>
		<description><![CDATA[Recently I&#8217;ve had to import a client&#8217;s catalog data from Excel 2007 to the Magento eCommerce Platform.  The data in Excel was unsurprisingly in a format that was unsupported by Magento&#8217;s import methods.  Using code, I needed to parse Excel data into the format Magento required.  In PHP, I wasn&#8217;t aware of [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve had to import a client&#8217;s catalog data from Excel 2007 to the Magento eCommerce Platform.  The data in Excel was unsurprisingly in a format that was unsupported by Magento&#8217;s import methods.  Using code, I needed to parse Excel data into the format Magento required.  In PHP, I wasn&#8217;t aware of any way to interface with .xls or .xlsx files, so I tried exporting the data to flat-file CSV, where it could be easily manipulated using PHP&#8217;s native CSV functions.</p>
<p><span id="more-352"></span>Unfortunately, none of the three CSV formats that Excel outputs could be properly parsed as CSV.  For example, accepted CSV standards state that values should be:</p>
<pre>"value1","value2","escaped "" double quote", "value 3", "", "", "7th column"</pre>
<p>But in Excel&#8217;s version of CSV, that would look like:</p>
<pre>value1,value2,"escaped "" double quote",value 3,,,7th column
</pre>
<p>It&#8217;s terribly inconsistent in its use of double quotes, confusing the hell out of many CSV parsers.</p>
<p><strong>The Solution:</strong></p>
<p><a title="CSV to XML Converter" href="http://www.creativyst.com/Prod/15/" class="external">CSV to XML Converter</a> by <a title="Creativyst" href="http://www.creativyst.com/" class="external">Creativyst(R)</a>.  It takes in CSV garbage and returns immaculate and clean XML.  Then use your language-of-choice&#8217;s XML functions to work with the data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nvncbl.com/2009/08/solution-to-excels-csv-output-formats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple List Reordering Technique</title>
		<link>http://www.nvncbl.com/2009/08/simple-list-reordering-technique/</link>
		<comments>http://www.nvncbl.com/2009/08/simple-list-reordering-technique/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 03:46:26 +0000</pubDate>
		<dc:creator>Antonio</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[technique]]></category>

		<guid isPermaLink="false">http://www.nvncbl.com/?p=276</guid>
		<description><![CDATA[At some point in our programming careers, we&#8217;ve had to reorder server-side (probably database driven) lists.  For example, allowing users to set the specific sequence that image thumbnails are displayed on the front-end of a photo album.
For &#8220;move-item-forwards&#8221; functionality, the logic may look like:

move_item_up&#40; index &#41;&#123;
  Store the element at index 3 to [...]]]></description>
			<content:encoded><![CDATA[<p>At some point in our programming careers, we&#8217;ve had to reorder server-side (probably database driven) lists.  For example, allowing users to set the specific sequence that image thumbnails are displayed on the front-end of a photo album.</p>
<p>For &#8220;move-item-forwards&#8221; functionality, the logic may look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">move_item_up<span style="color: #009900;">&#40;</span> index <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  Store the element at index <span style="color: #cc66cc;">3</span> to a temporary variable<span style="color: #339933;">.</span>
  Set the value of index <span style="color: #cc66cc;">3</span> to the value of index <span style="color:#800080;">4.</span>
  Set the value of index <span style="color: #cc66cc;">4</span> to the temporary variable<span style="color: #0000ff;">'s value.
}</span></pre></div></div>

<p>The &#8220;technique&#8221; comes into play now, when you have to do the &#8220;move-item-backwards&#8221; functionality.</p>
<p>Instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">move_item_back<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Simply use:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">move_item_up<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Moving an item backwards in a list is the same as moving the previous item forwards.  This technique is rather simple and perhaps painfully obvious to some, though it may be useful to others.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nvncbl.com/2009/08/simple-list-reordering-technique/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP HTTP Class 2</title>
		<link>http://www.nvncbl.com/2008/12/php-http-class-2/</link>
		<comments>http://www.nvncbl.com/2008/12/php-http-class-2/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 16:21:18 +0000</pubDate>
		<dc:creator>Antonio</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.nvncbl.com/?p=100</guid>
		<description><![CDATA[Revisiting the topic of my previous post, I&#8217;ve played around some more with this PHP HTTP Class.  This morning, I&#8217;ve figured out how to send files over HTTP (actually HTTPS, but it works the same way).  If you&#8217;ve looked through the author&#8217;s test scripts, you see that for file uploads, the provided example [...]]]></description>
			<content:encoded><![CDATA[<p>Revisiting the topic of my <a title="PHP HTTP Class" href="http://www.nvncbl.com/index.php/2008/12/php-http-class/" class="external">previous post</a>, I&#8217;ve played around some more with this <a title="PHP HTTP Class" href="http://www.phpclasses.org/browse/package/3.html" class="external">PHP HTTP Class</a>.  This morning, I&#8217;ve figured out how to send files over HTTP (actually HTTPS, but it works the same way).  If you&#8217;ve looked through the author&#8217;s test scripts, you see that for file uploads, the provided example is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arguments</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PostFiles&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">&quot;userfile&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;Data&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;This is just a plain text attachment file.&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;Name&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;attachment.txt&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;Content-Type&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;automatic/name&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">&quot;anotherfile&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;FileName&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;test_http_post.php&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;Content-Type&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;automatic/name&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-100"></span>So it&#8217;s actually pretty easy to send files.  This class provides two methods, as we&#8217;ve seen in the example.</p>
<ul>
<li><strong>userfile:</strong> The first example sends raw data and provides a filename</li>
<li><strong>anotherfile:</strong> The second example sends  the file specified in FileName</li>
</ul>
<p>Happy uploading!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nvncbl.com/2008/12/php-http-class-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP HTTP Class</title>
		<link>http://www.nvncbl.com/2008/12/php-http-class/</link>
		<comments>http://www.nvncbl.com/2008/12/php-http-class/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 00:18:25 +0000</pubDate>
		<dc:creator>Antonio</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://www.nvncbl.com/?p=94</guid>
		<description><![CDATA[I&#8217;ve found a great PHP script that can essentially turn a web server into a virtual browser.  The script is small and lightweight compared to existing solutions (just 62KB) and it isn&#8217;t dependent on anything else.  I needed it for sending/receiving data through POST (because GET is easy), and more importantly, doing it over SSL.  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found a great <a title="PHP HTTP Class" href="http://www.phpclasses.org/browse/package/3.html" class="external">PHP script</a> that can essentially turn a web server into a virtual browser.  The script is small and lightweight compared to existing solutions (just 62KB) and it isn&#8217;t dependent on anything else.  I needed it for sending/receiving data through POST (because GET is easy), and more importantly, doing it over SSL.  I still need to figure out how to upload files through this, but I don&#8217;t think it should be too big of an issue.  I&#8217;m sure it&#8217;s just a matter of encoding.</p>
<p><span id="more-94"></span>The script was found at <a title="PHP Classes" href="http://www.phpclasses.org" class="external">PHP Classes</a>, a resource I regularly tap into.  You&#8217;ll discover that PHP Classes requires registration, but it&#8217;s free and you can disable any email notifications.  Also, don&#8217;t be turned off by the website&#8217;s aesthetics, they were apparently going for &#8220;functional&#8221;.  Hey, it worked for <a title="Craigslist" href="http://www.craigslist.com" class="external">Craigslist</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nvncbl.com/2008/12/php-http-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

