<?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>CaptainCodeMonkey.com - All Your Booty Are Belong To Us! &#187; PHP</title>
	<atom:link href="http://www.captaincodemonkey.com/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.captaincodemonkey.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 01 May 2010 22:43:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Code Get Most Recent WordPress Post</title>
		<link>http://www.captaincodemonkey.com/blog/2010/01/24/php-code-get-most-recent-wordpress-post/</link>
		<comments>http://www.captaincodemonkey.com/blog/2010/01/24/php-code-get-most-recent-wordpress-post/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 03:25:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Programming]]></category>
		<category><![CDATA[Programming - General]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.captaincodemonkey.com/blog/?p=420</guid>
		<description><![CDATA[PHP Code Get Most Recent WordPress Post﻿ This is a quick example using only vanilla PHP.  There are more dynamic ways to do this using RSS classes built into PHP addons, which I won&#8217;t go into detail here.  Instead, we will just use vanilla PHP, and parse the XML by hand. On to the code, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>PHP Code Get Most Recent WordPress Post﻿</strong></p>
<p>This is a quick example using only vanilla PHP.  There are more dynamic ways to do this using RSS classes built into PHP addons, which I won&#8217;t go into detail here.  Instead, we will just use vanilla PHP, and parse the XML by hand.</p>
<p>On to the code, I take 3 arguments here, number of posts to return, the RSS URL, and an optional max number of characters to return.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p420code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4203"><td class="code" id="p420code3"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//get most recent rss</span>
<span style="color: #666666; font-style: italic;">//get most recent rss</span>
<span style="color: #000000; font-weight: bold;">function</span> recent_rss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$display</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description_limit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$itemArr</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$display</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//if limit passed in, truncate string</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$description_limit</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$description</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description_limit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;...&quot;</span><span style="color: #339933;">;</span> 	
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$itemRSS</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'title'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$description</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'link'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'pubdate'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pubDate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <a href="http://www.php.net/array_push"><span style="color: #990000;">array_push</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$itemArr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$itemRSS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$display</span><span style="color: #339933;">--;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$itemArr</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//example use</span>
<span style="color: #000088;">$recent_post</span> <span style="color: #339933;">=</span> recent_rss<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://houseplansblog.nelsondesigngroup.com/index.php/feed/'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recent_post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, Here is a quick and dirty XHTML example showing how you might implement this on a page. (Note the use of the preg_replace to get rid of weird characters that get into the RSS sometimes)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p420code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4204"><td class="code" id="p420code4"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rss_container&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;width:250px;&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rss_title&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">'&lt;?php echo $recent_post[0][&quot;link&quot;]; ?&gt;'</span><span style="color: #339933;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[^(\x20-\x7F)]*/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$recent_post</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rss_pub_date&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$recent_post</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;pubdate&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rss_description&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$recent_post</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.captaincodemonkey.com/blog/2010/01/24/php-code-get-most-recent-wordpress-post/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Write Code In The Dark</title>
		<link>http://www.captaincodemonkey.com/blog/2009/07/10/dont-write-code-in-the-dark/</link>
		<comments>http://www.captaincodemonkey.com/blog/2009/07/10/dont-write-code-in-the-dark/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 03:36:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Programming]]></category>
		<category><![CDATA[Programming - General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.captaincodemonkey.com/blog/?p=193</guid>
		<description><![CDATA[Don&#8217;t Write Code In The Dark&#8230; I may be showing my age a little bit here but I remember watching Are You Afraid Of The Dark? on Nick as a kid.  It was quite a cheezy show, but hey what do you expect. Do you know what happens to people during sensory deprivation? (A brief [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-194" style="padding:5px;" title="afraidofthedark01" src="http://www.captaincodemonkey.com/blog/wp-content/uploads/2009/07/afraidofthedark01-251x300.gif" alt="afraidofthedark01" width="251" height="300" /> <strong>Don&#8217;t Write Code In The Dark&#8230;</strong></p>
<p>I may be showing my age a little bit here but I remember watching Are You Afraid Of The Dark? on Nick as a kid.  It was quite a cheezy show, but hey what do you expect.</p>
<p>Do you know what happens to people during sensory deprivation? (A brief introduction can be found <a href="http://en.wikipedia.org/wiki/Sensory_deprivation">here</a>). &#8220;Though short periods of sensory deprivation can be <span class="mw-redirect">relaxing</span>, extended deprivation can result in extreme anxiety, <span class="mw-redirect">hallucinations</span>, bizarre thoughts, depression&#8230;&#8221;</p>
<p>So think about what happens when you are DEPRIVED of the senses befitting a modern developer.  If you are in a situation where you are the ONLY developer, then you are at a much greater risk.  It could be that your employeer has cut you off from the outside world, or maybe you have cut yourself off.</p>
<p>You will write much better code if you don&#8217;t try to do it in the dark.  Having other developers around you to bounce ideas off of is amazing, but if your in a situation where you don&#8217;t have that luxury, then you can find sources on the internet.  Use a chat system if you can, use twitter, get involved in developer comunities, ask questions you don&#8217;t know, and answer questions other developers have that you know the answers to.  This will allow you to build relationships with other developers who have different skill sets and ways of approaching problems.</p>
<p>Check out <a href="http://www.wired.com/techbiz/people/news/2007/07/coworking">casual coworking</a> (jelly!) , as this can be a really great way to avoid writing code in the dark, and it is something that really seems to be taking off.  Look around, there may be one of these in your area, and if not, it could be a good time to start one.  If your around my area, you might be suprised to know about<a href="http://www.jonesborocoworking.com/"> Jonesboro Co-Working</a>.</p>
<p>The days of locking yourself away in a room for weeks on end and emerging with a finished product are over, get with the program, and stop writing code in the dark!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.captaincodemonkey.com/blog/2009/07/10/dont-write-code-in-the-dark/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Get The Last MySQL Auto-ID in PHP</title>
		<link>http://www.captaincodemonkey.com/blog/2008/03/06/how-to-get-the-last-mysql-auto-id-in-php/</link>
		<comments>http://www.captaincodemonkey.com/blog/2008/03/06/how-to-get-the-last-mysql-auto-id-in-php/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 16:04:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Programming]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[last auto id]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.aprogrammingpro.com/2008/03/06/how-to-get-the-last-mysql-auto-id-in-php/</guid>
		<description><![CDATA[There will be times when you will need to retrieve the last auto id on a table where you just did an insert. They way to do this is as follows: &#60;?php $link = mysql_connect(&#8216;host&#8217;, &#8216;user&#8217;, &#8216;pass&#8217;); if(!$link) { die(&#8216;could not connect: &#8216;. mysql_error() ) ; } mysql_query(&#8220;INSERT INTO table (field) values (&#8216;val1&#8242;)&#8221; ); echo [...]]]></description>
			<content:encoded><![CDATA[<p>There will be times when you will need to retrieve the last auto id on a table where you just did an insert.  They way to do this is as follows:</p>
<blockquote><p>&lt;?php</p>
<p>$link = mysql_connect(&#8216;host&#8217;, &#8216;user&#8217;, &#8216;pass&#8217;);</p>
<p>if(!$link)<br />
{<br />
die(&#8216;could not connect: &#8216;. mysql_error() ) ;<br />
}</p>
<p>mysql_query(&#8220;INSERT INTO table (field) values (&#8216;val1&#8242;)&#8221; );</p>
<p>echo &#8220;Last ID is &#8220;.mysql_insert_id());</p></blockquote>
<p>Be sure you do this directly after the insert, if you need to use it for something, because it changes anytime another insert is done on a table with an auto id.</p>
<p>I have also noticed weird results on the first entry of a blank table, so watch out for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.captaincodemonkey.com/blog/2008/03/06/how-to-get-the-last-mysql-auto-id-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Permanently Move A Page</title>
		<link>http://www.captaincodemonkey.com/blog/2008/03/01/php-permanently-move-a-page/</link>
		<comments>http://www.captaincodemonkey.com/blog/2008/03/01/php-permanently-move-a-page/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 23:06:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[301 redirect]]></category>
		<category><![CDATA[move a page]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.aprogrammingpro.com/2008/03/01/php-permanently-move-a-page/</guid>
		<description><![CDATA[The proper way to move a page and have search engines properly find it is to use a 301 redirect. The 301 redirect tells the search engines that &#8220;this page has permanently moved&#8221;. I am in the process of redirecting an entire website using 301 redirects, and I will post updates on the impact this [...]]]></description>
			<content:encoded><![CDATA[<p>The proper way to move a page and have search engines properly find it is to use a 301 redirect.  The 301 redirect tells the search engines that &#8220;this page has permanently moved&#8221;.  I am in the process of redirecting an entire website using 301 redirects, and I will post updates on the impact this has on the SEO and search engine placement on the site.  The code to do a 301 redirect in php is as follows:</p>
<blockquote>
<pre><code>&lt;?php

// Permanent redirection

header("HTTP/1.1 301 Moved Permanently");

header("Location: http://www.somacon.com/");

exit();</code></pre>
<pre><code>?&gt;</code></pre>
</blockquote>
<p>Be sure you put the line : header(&#8220;HTTP/1.1 301 Moved Permanently&#8221;); Because as I have recently discovered, just using the header location line does a 302 redirect instead of a 301.  A 302 redirect tells the search engines that &#8220;this page has temporarily moved&#8221;.  So be sure you do this correctly if the page is permanently moving.</p>
<blockquote></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.captaincodemonkey.com/blog/2008/03/01/php-permanently-move-a-page/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Easy PHP and Html Bar Graph</title>
		<link>http://www.captaincodemonkey.com/blog/2008/02/25/easy-php-and-html-bar-graph/</link>
		<comments>http://www.captaincodemonkey.com/blog/2008/02/25/easy-php-and-html-bar-graph/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 16:10:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Programming]]></category>
		<category><![CDATA[Easy Bar Graph]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.aprogrammingpro.com/2008/02/25/easy-php-and-html-bar-graph/</guid>
		<description><![CDATA[I want to show you a quick and simple way to create a bar graph using HTML. You need a graphic file that&#8217;s just 1 pixel wide and 5 px tall. Make it whatever color you want your bars to be. I named mine CountBar.gif. In my example, I have an array of data for [...]]]></description>
			<content:encoded><![CDATA[<p>I want to show you a quick and simple way to create a bar graph using HTML.</p>
<p>You need a graphic file that&#8217;s just 1 pixel wide and 5 px tall.  Make it whatever color you want your bars to be.   I named mine CountBar.gif.</p>
<p>In my example, I have an array of data for each month, containing sales.  The key part to the whole concept can be seen here: (the table was created prior to this code block, and is ended after, I am just showing you the relevant section.</p>
<p>Basically, we loop through each month, $arrMonths contains the string values of each month like &#8220;January&#8221;, ect.  $arrResults[$i]; contains the sales values for each corresponding month.  (don&#8217;t get confused by my arrays, just focus on the concept).</p>
<p>The Key part is here:  We set the width of the graphic equal to the amount of sales for the month divided by a static variable (we use this to keep the widths in a relative range, in this case, i know my sales data ranges from 0-50,000 so I want the width of my graph to go from 0-500 pixels)</p>
<p><strong>&lt;img src=&#8221;countBar.gif&#8221; width=&#8221;&lt;?php echo intval($arrResults[$i] / 100);<br />
$total += $arrResults[$i]; ?&gt;&#8221; height=&#8221;5&#8243; class=&#8221;chart&#8221;&gt; </strong></p>
<blockquote><p>&lt;?php</p>
<p>$total = 0;</p>
<p>for ($i = 0; $i &lt; 12; $i++) {<br />
?&gt;<br />
&lt;tr&gt;<br />
&lt;td width=&#8221;15%&#8221; height=&#8221;12&#8243; align=&#8221;left&#8221; valign=&#8221;middle&#8221;&gt;&lt;?php echo $arrMonths[$i + 1].&#8221;     &#8220;;?&gt;&lt;/td&gt;&lt;td width=&#8221;15%&#8221; height=&#8221;12&#8243; align=&#8221;left&#8221; valign=&#8221;middle&#8221;&gt;$&lt;?php echo &#8221; &#8220;.$arrResults[$i]; ?&gt;: &lt;/td&gt;<br />
&lt;td width=&#8221;70%&#8221; height=&#8221;12&#8243;&gt;&lt;img src=&#8221;countBar.gif&#8221; width=&#8221;&lt;?php echo intval($arrResults[$i] / 100);<br />
$total += $arrResults[$i]; ?&gt;&#8221; height=&#8221;5&#8243; class=&#8221;chart&#8221;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;?php<br />
}<br />
?&gt;</p></blockquote>
<p>And you can get something like this: ( i have marked out the  actual values on purpose)<img src="http://www.aprogrammingpro.com/Untitled-1.gif" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.captaincodemonkey.com/blog/2008/02/25/easy-php-and-html-bar-graph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Quick Reference Study Guide</title>
		<link>http://www.captaincodemonkey.com/blog/2008/02/17/php-quick-reference-study-guide/</link>
		<comments>http://www.captaincodemonkey.com/blog/2008/02/17/php-quick-reference-study-guide/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 03:37:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Programming]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<category><![CDATA[Study Guide]]></category>

		<guid isPermaLink="false">http://www.aprogrammingpro.com/2008/02/17/php-quick-reference-study-guide/</guid>
		<description><![CDATA[Comments In PHP #this is a comment, to EOL //this is also a comment, to EOL /* This is also a comment For multi lines */ Variables &#160; Must start with (A-Za-z) or _(underscore) like: $blah $_blah $H4x0rs Illegial Variables $7337 $*UCK Variables in PHP are loosely typed, and do not need to be declared [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Comments In PHP</strong></p>
<p id="blah1" style="margin-left: 10px"> #this is a comment, to EOL</p>
<p>//this is also a comment, to EOL</p>
<p>/* This is also a comment</p>
<p>For multi lines</p>
<p>*/</p>
<p><strong>Variables</strong></p>
<p id="blah2" style="margin-left: 10px">&nbsp;</p>
<p>	Must start with (A-Za-z) or _(underscore)</p>
<p>like:</p>
<p>$blah</p>
<p>$_blah</p>
<p>$H4x0rs</p>
<p>Illegial Variables</p>
<p>$7337</p>
<p>$*UCK</p>
<p>Variables in PHP are loosely typed, and do not need to be declared prior to use.</p>
<p>So the following are all legal statements</p>
<p>$shane = &#8220;Shane Is Leet&#8221;;</p>
<p>$shane = 10 * 4 + 3;</p>
<p>Variable types in php are interchangeable, so I used the variable $shane as a string in one line, and then as an integer in another, and php dosen&#8217;t mind at all.</p>
<p>PHP does support indirect variable references, but I personally don&#8217;t use them.  Here is a brief example:</p>
<p>$var1 = &#8220;Shane&#8221;;</p>
<p>$$var1 = &#8220;Who Is The 7337&#8243;;<br />
print $Shane; # this will output &#8220;Who Is The 7337&#8243;</p>
<p>You can use as many levels of indirection as you can stomach.</p>
<p><strong>Variable Management</strong></p>
<ul>
<li>isset()</li>
<li>unset()</li>
<li>empty()</li>
</ul>
<p>isset() example:</p>
<p>if(isset($shane) {</p>
<p>print &#8216;$shane is set&#8217;;</p>
<p>}</p>
<p>unset() example:</p>
<p>unset($shane);</p>
<p>if(!isset($shane)) {</p>
<p>echo &#8216;$shane is unset&#8217;;</p>
<p>}</p>
<p>empty() is typically used to check form values, the variables value is converted to a bool, then checked for true/false, example:</p>
<p>if (empty($shane)) {</p>
<p>print &#8216;Error: $shane is empty&#8217;;</p>
<p>}<br />
This prints the error message if $shane dosen&#8217;t contain a value that evaluates to true.</p>
<p><strong>Data Types</strong></p>
<p>PHP Suports, Integer, Hex (like 0xABCD) &#8211; Values (-100)</p>
<p>Floating Point like: 3.14, +0.1e-4, -1600.3, 22.6E42</p>
<p>Strings:</p>
<p>PHP supports strings, beginning and ending with single or double quotes, and allows embedding of variables like in the previous examples.</p>
<p>When using single quotes, you lose some of the escape characters support when using double quotes</p>
<p>Double Quote Escape Characters:</p>
<ul>
<li>\n #newline</li>
<li>\t #Tab</li>
<li>\&#8221; #double quote</li>
<li>\\ #backslash</li>
<li>\0 #ASCII 0 (null)</li>
<li>\r #linefeed</li>
<li>\$ #the character $</li>
<li>\(Octal # ) #ex \70 would be the letter 8</li>
<li>\x(hex #) # like \0&#215;32 is the letter 2</li>
</ul>
<p>Single Quote Escape Characters:</p>
<ul>
<li> \&#8217; #single uote</li>
<li> \\ #backslash</li>
</ul>
<p><strong>Null</strong></p>
<p>Null is a data type with only one value: the NULL value. Use it thusly:</p>
<p>$shane = NULL;</p>
<p><strong>Arrays</strong></p>
<p>Straitforward, array(1, 2, 3) or array(0 =&gt; 1, 1 =&gt; 2, 2 =&gt;3)</p>
<p>$var1 = array(&#8220;name&#8221; =&gt; &#8220;Shane&#8221;, &#8220;age&#8221; =&gt; &#8220;28&#8243;);</p>
<p>echo $var1["name"]; #prints &#8220;Shane&#8221;</p>
<p>There is quite a lot to arrays in php, so for more info check <a href="http://www.php.net/manual/en/language.types.array.php">Arrays In PHP</a></p>
<p>To Iterate across the array, I typically use <strong>foreach()</strong></p>
<p>$players = array(&#8220;Shane&#8221;, &#8220;Craig&#8221;, &#8220;Sandra&#8221;, &#8220;Meme&#8221;);</p>
<p>foreach($players as $key =&gt; $value) {</p>
<p>print &#8220;#$key = $value\n&#8221;;<br />
}</p>
<p>Output is:</p>
<p>#0 = Shane</p>
<p>#1 = Craig</p>
<p>#2 = Sandra</p>
<p>#3 = Meme</p>
<p>You can also traverse the array using list() and each(), which I will not go over here.</p>
<p>More to come later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.captaincodemonkey.com/blog/2008/02/17/php-quick-reference-study-guide/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
