<?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>Ryan Price &#187; PHP</title>
	<atom:link href="http://www.ryanprice.ca/category/technology/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryanprice.ca</link>
	<description>The definitive proof that I'm a geek at heart</description>
	<lastBuildDate>Wed, 01 Sep 2010 18:23:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to Easily Document Your PHP Code</title>
		<link>http://www.ryanprice.ca/how-to-easily-document-your-php-code/</link>
		<comments>http://www.ryanprice.ca/how-to-easily-document-your-php-code/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 22:40:04 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/?p=31</guid>
		<description><![CDATA[So you&#8217;ve spent all sorts of time developing an amazing PHP application. You want to share your awesomeness with the world. The only problem is you hate writing documentation. No problem! PHPdoc to the rescue! If you write your application with PHPdoc in mind, then your documentation will be done when the application is! All [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-easily-document-your-php-code/">How to Easily Document Your PHP Code</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve spent all sorts of time developing an amazing PHP application.  You want to share your awesomeness with the world.  The only problem is you hate writing documentation.  No problem!</p>
<p><a href="http://www.phpdoc.org/" target="_blank">PHPdoc</a> to the rescue!</p>
<p>If you write your application with PHPdoc in mind, then your documentation will be done when the application is!  All you need to do is comment your functions/methods using the correct form, and PHPdoc will handle all the documentation.</p>
<p>For those who are more familiar with Java, this may sound familiar (and for good reason).  This is PHP&#8217;s version of JavaDoc.  So if you&#8217;ve used JavaDoc before then phpDoc will be a breeze.</p>
<p>Check out their site at <a href="http://www.phpdoc.org/" target="_blank">http://www.phpdoc.org/</a> for more.  Enjoy!</p>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price&#8217;s blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-easily-document-your-php-code/">How to Easily Document Your PHP Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-easily-document-your-php-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Automatically Create Getter and Setter Methods in PHP</title>
		<link>http://www.ryanprice.ca/how-to-automatically-create-getter-and-setter-methods-in-php/</link>
		<comments>http://www.ryanprice.ca/how-to-automatically-create-getter-and-setter-methods-in-php/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 22:38:33 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Snippets]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/?p=30</guid>
		<description><![CDATA[In PHP 5+, PHP has introduced a handy little function __call() that is used as a type of last resort when the function being called can not be found within the class. By utilizing this feature, we are able to write generic code that will create getter and setter methods for each attribute in your [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-automatically-create-getter-and-setter-methods-in-php/">How to Automatically Create Getter and Setter Methods in PHP</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In PHP 5+, PHP has introduced a handy little function <tt>__call()</tt> that is used as a type of last resort when the function being called can not be found within the class.  By utilizing this feature, we are able to write generic code that will create getter and setter methods for each attribute in your class.<br />
<span id="more-30"></span></p>
<p>Not only does this create a getter and setter method for each attribute, but it also means that no maintenance to getter and setter methods are required when you add or remove attributes at a later point.</p>
<p>Lets take a look at a sample class called <tt>Picture</tt> which simply describes an image that is stored on the server at some URL.</p>
<pre name="code" class="php">
class Picture {

	protected $id;
	protected $type;
	protected $width;
	protected $height;
	protected $name;
	protected $url;

	public function setID($id) {
		if (!$this->id) {
			$this->id = $id;
		}
	}

	/**
	 * This serves as the default getter and setter methods for all attributes that don't expressively have one
	 *
	 * @param unknown_type $name
	 * @param unknown_type $args
	 * @return unknown nothing
	 */
	public function __call($name, $args) {
		if (preg_match('/^(get|set)(w+)/', strtolower($name), $match) &#038;&#038; $attribute = $this->validateAttribute($match[2])) {
			if ('get' == $match[1]) {
				return $this->$attribute;
			} else {
				$this->$attribute = $args[0];
			}
		} else {
			throw new Exception('Call to undefined method Bookmark::'.$name.'()');
		}
	}

	/**
	 * Validates that the attribute is part of the class
	 *
	 * @param unknown_type $name name of the attribute
	 * @return unknown returns the name of the attribute
	 */
	protected function validateAttribute($name) {
		if (in_array(strtolower($name), array_keys(get_class_vars(get_class($this))))) {
			return strtolower($name);
		}
	}
}
</pre>
<p>The code above in <tt>__call()</tt> and <tt>validateAttribute</tt> is used as the getter and setter functions for any attribute <em>which does not already have a getter or setter defined</em>.  This is important to note.  <tt>__call()</tt> is only used as a last resort.  Therefore, if you want to create a getter or setter that behaves differently then normal it is not a problem.  In fact, that is exactly what I have done for <tt>setID</tt>.</p>
<p>In this case, the ID is not something we want to be overridden once it is set.  In my case, the purpose of this ID was to identify the picture&#8217;s ID in the database.  So once the ID is set (likely when the object is created), the ID can no longer be changed.</p>
<p>Feel free to leave questions in the comments, I&#8217;ll be happy to answer.</p>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price&#8217;s blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-automatically-create-getter-and-setter-methods-in-php/">How to Automatically Create Getter and Setter Methods in PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-automatically-create-getter-and-setter-methods-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Avoid Problems with max_user_connections in PHP/SQL with 3 Simple Rules</title>
		<link>http://www.ryanprice.ca/how-to-avoid-problems-with-max_user_connections-in-phpsql-with-3-simple-rules/</link>
		<comments>http://www.ryanprice.ca/how-to-avoid-problems-with-max_user_connections-in-phpsql-with-3-simple-rules/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 18:10:32 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[Facebook Platform]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/how-to-avoid-problems-with-max_user_connections-in-phpsql-with-3-simple-rules/</guid>
		<description><![CDATA[Since the launch of my Fantasy Stock Picking Game for Facebook last weekend I've experienced a large increase in users (gone from about 60 to just under 3000). This meant that I had to make sure my code was as efficient as possible. Last night I took the time out to go through the code [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-avoid-problems-with-max_user_connections-in-phpsql-with-3-simple-rules/">How to Avoid Problems with max_user_connections in PHP/SQL with 3 Simple Rules</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Since the launch of my <a href="http://apps.facebook.com/stockpicking" target="_blank">Fantasy Stock Picking Game for Facebook</a> last weekend I've experienced a large increase in users (gone from about 60 to just under 3000).</p>
<p>This meant that I had to make sure my code was as efficient as possible.  Last night I took the time out to go through the code to ensure I hadn't overlooked anything.  Turns out I had, and it was causing <abbr title="The maximum number of connections you can have at one time to an SQL database">max_user_connections</abbr> to be exceeded (meaning some people would have problems accessing the game at certain points).</p>
<p>So in order to save yourself the hassle of going through your code like I did, let me help you cut the problem off at the pass and avoid it all together with a few simple rules:<br />
<span id="more-23"></span></p>
<h4>1. Open your connections just before you run the query, and close them immediately after.</h4>
<p>I was opening the connection at the beginning of a file, and then closing it at the end.  This meant that I was unnecessarily tying up a connection (and I only get 15) while information was being processed.</p>
<h4>2. Put your DB connection code in a function</h4>
<p>This ties in with the first suggestion.  Many people include the connection code in a header file or similar to ensure that the database connection is there when they need it.  This is inefficient.  Put your connection code into a function, call the function, and return the connection resource.</p>
<div class="igBar"><span id="lphp-2"><a href="#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//Connect to the database</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> get_db_conn<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$conn</span> = <a href="http://www.php.net/mysql_connect"><span style="color:#000066;">mysql_connect</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$GLOBALS</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'db_ip'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF;">$GLOBALS</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'db_user'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF;">$GLOBALS</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'db_pass'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> or <a href="http://www.php.net/die"><span style="color:#000066;">die</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Unable to Connect to server"</span>. <a href="http://www.php.net/mysql_error"><span style="color:#000066;">mysql_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/mysql_select_db"><span style="color:#000066;">mysql_select_db</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$GLOBALS</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'db_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF;">$conn</span><span style="color:#006600; font-weight:bold;">&#41;</span> or <a href="http://www.php.net/die"><span style="color:#000066;">die</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Unable to Connect to database"</span>. <a href="http://www.php.net/mysql_error"><span style="color:#000066;">mysql_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$conn</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h4>3. Remember that its not only <tt>mysql_query()</tt> that needs a connection!</h4>
<p>If you're using forms at all, you should be <a href="http://www.ryanprice.ca/work/how-to-make-your-form-data-safe-for-mysql-with-php/" target="_blank">ensuring that they are secure</a> before you use it in the database.  What many people don't know is that <tt>mysql_real_escape_string()</tt> needs an active connection to the database to work, so make sure that you have an open connection before using this function.</p>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-avoid-problems-with-max_user_connections-in-phpsql-with-3-simple-rules/">How to Avoid Problems with max_user_connections in PHP/SQL with 3 Simple Rules</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-avoid-problems-with-max_user_connections-in-phpsql-with-3-simple-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create a Quick Image Gallery in PHP</title>
		<link>http://www.ryanprice.ca/how-to-create-a-quick-image-gallery-in-php/</link>
		<comments>http://www.ryanprice.ca/how-to-create-a-quick-image-gallery-in-php/#comments</comments>
		<pubDate>Wed, 23 May 2007 19:02:53 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/?p=18</guid>
		<description><![CDATA[Introduction There are so many gallery scripts out there for PHP you may be wondering why I'm even bothering with a how-to on this subject. Well, if you're like me then you often need a quick and simple gallery rather than trying to use pre-made scripts that require heavy integration into your design. Here's how [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-create-a-quick-image-gallery-in-php/">How to Create a Quick Image Gallery in PHP</a></p>
]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>There are so many gallery scripts out there for PHP you may be wondering why I'm even bothering with a how-to on this subject.  Well, if you're like me then you often need a quick and simple gallery rather than trying to use pre-made scripts that require heavy integration into your design.  Here's how I do it.<br />
<span id="more-18"></span></p>
<p>As with all the articles I write here, this is something I've used before when creating sites for clients.  To see an example of what we'll be creating you can visit <a href="http://www.reachingintoheaven.com/gallery.php" target="_blank">ReachingIntoHeaven.com's gallery page</a>.  </p>
<p>That gallery has a few bells and whistles that you may not need, so I'll be toning things down to start.  However, if you're interested in the bells and whistles I will also briefly cover a few quick ideas on how you can increase the usefulness and eye-appeal of this little script.</p>
<p>Here's an overview of the steps we'll be taking:</p>
<ul>
<li>How to store your images to make life easier</li>
<li>Creating the template</li>
<li>Adding the functionality with PHP</li>
<li><b>Bonus:</b> Adding the razzle-dazzle</li>
</ul>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-create-a-quick-image-gallery-in-php/">How to Create a Quick Image Gallery in PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-create-a-quick-image-gallery-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Preload an Entire Directory of Images Using Javascript and PHP</title>
		<link>http://www.ryanprice.ca/how-to-preload-an-entire-directory-of-images-using-javascript-and-php/</link>
		<comments>http://www.ryanprice.ca/how-to-preload-an-entire-directory-of-images-using-javascript-and-php/#comments</comments>
		<pubDate>Mon, 14 May 2007 19:54:56 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/?p=16</guid>
		<description><![CDATA[Why Preload? The main reason you want to preload images is when they are being used for mouse-over or roll-over effects. If they're not displayed by the page when it loads then the page will wait until the image is needed to load it. However, this can result in a delay to the mouse-over/rollover effect [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-preload-an-entire-directory-of-images-using-javascript-and-php/">How to Preload an Entire Directory of Images Using Javascript and PHP</a></p>
]]></description>
			<content:encoded><![CDATA[<h3>Why Preload?</h3>
<p>The main reason you want to preload images is when they are being used for mouse-over or roll-over effects.  If they're not displayed by the page when it loads then the page will wait until the image is needed to load it.  However, this can result in a delay to the mouse-over/rollover effect while the image loads.  In steps the preload.<br />
<span id="more-16"></span><br />
Before we dig into how this works, I'll provide the finished code for those who just want to copy and paste.  As always, click the "PLAIN TEXT" above the code to view it in a copy &#038; paste friendly format.  For those who want to know how it works, read on.</p>
<div class="igBar"><span id="lphp-5"><a href="#" onclick="javascript:showPlainTxt('php-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-5">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//This function will cycle through the directory it is sent</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//$x is used to count the number of images, we set it to 0 by default</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> preloadImages<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span>, <span style="color:#0000FF;">$x</span> = <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//first, lets make sure the user sent a directory.&nbsp; If they didn't, return &quot;false&quot;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the path has a slash at the end we remove it here</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span>,-<span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#FF0000;">'/'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$directory</span> = <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span>,<span style="color:#CC66CC;color:#800000;">0</span>,-<span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the path is not valid or is not a directory ...</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color:#000066;">file_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span> || !<a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... we return false and exit the function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">FALSE</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... if the path is not readable</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/is_readable"><span style="color:#000066;">is_readable</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... we return false and exit the function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">FALSE</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... else if the path is readable</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we open the directory</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$handle</span> = <a href="http://www.php.net/opendir"><span style="color:#000066;">opendir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// and scan through the items inside</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">while</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$item</span> = <a href="http://www.php.net/readdir"><span style="color:#000066;">readdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$handle</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>!== <span style="color:#000000; font-weight:bold;">FALSE</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the filepointer is not the current directory</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// or the parent directory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$item</span> != <span style="color:#FF0000;">'.'</span> &amp;&amp; <span style="color:#0000FF;">$item</span> != <span style="color:#FF0000;">'..'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we build the new path to access</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$path</span> = <span style="color:#0000FF;">$directory</span>.<span style="color:#FF0000;">'/'</span>.<span style="color:#0000FF;">$item</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the new path is a directory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$path</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we call this function with the new path, and the current counter</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; preloadImages<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$path</span>, <span style="color:#0000FF;">$x</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the new path is a file</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we get the file info</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/list"><span style="color:#000066;">list</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$width</span>, <span style="color:#0000FF;">$height</span>, <span style="color:#0000FF;">$type</span>, <span style="color:#0000FF;">$attr</span><span style="color:#006600; font-weight:bold;">&#41;</span> = <a href="http://www.php.net/getimagesize"><span style="color:#000066;">getimagesize</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$path</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//and output the javascript code</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"pic"</span>.<span style="color:#0000FF;">$x</span>.<span style="color:#FF0000;">" =&nbsp; new Image("</span>.<span style="color:#0000FF;">$width</span>.<span style="color:#FF0000;">","</span>.<span style="color:#0000FF;">$height</span>.<span style="color:#FF0000;">");<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"pic"</span>.<span style="color:#0000FF;">$x</span>.<span style="color:#FF0000;">".src=<span style="color:#000099; font-weight:bold;">\"</span>"</span>.<span style="color:#0000FF;">$path</span>.<span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\"</span>;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<span style="color:#0000FF;">$x</span>++;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// close the directory</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/closedir"><span style="color:#000066;">closedir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$handle</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// return success</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">TRUE</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>To implement it, place it in the <tt>head</tt> section of your document like so:</p>
<div class="igBar"><span id="lhtml-6"><a href="#" onclick="javascript:showPlainTxt('html-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-6">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">language</span>=<span style="color: #ff0000;">"JavaScript"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">if (document.images)</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">{</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"></li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&lt;?php preloadImages(&quot;images&quot;) or die (&quot;Unable to preload images&quot;); ?&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">}</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">//--&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><tt>images</tt> is the location of the images directory (in this case, its at the same level as the file that the javascript code is in).  You may have to change this to match yours.</p>
<p><strong>Note: This assumes that all files in the directory and sub-directories are images</strong></p>
<p>Now lets go through the code and analyze whats happening.</p>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-preload-an-entire-directory-of-images-using-javascript-and-php/">How to Preload an Entire Directory of Images Using Javascript and PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-preload-an-entire-directory-of-images-using-javascript-and-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Create a Class in PHP</title>
		<link>http://www.ryanprice.ca/how-to-create-a-class-in-php/</link>
		<comments>http://www.ryanprice.ca/how-to-create-a-class-in-php/#comments</comments>
		<pubDate>Wed, 09 May 2007 13:57:14 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/?p=6</guid>
		<description><![CDATA[Introduction to Object Oriented Programming Object Oriented Programming (OOP) can be extremely handy in many situations. A class is a way of grouping all the variables and functions relating to a specific object in one place. If you read that sentence and went Huh? don't worry. I found that Object Oriented Programming and dealing with [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-create-a-class-in-php/">How to Create a Class in PHP</a></p>
]]></description>
			<content:encoded><![CDATA[<h3>Introduction to Object Oriented Programming</h3>
<p>Object Oriented Programming (OOP) can be extremely handy in many situations. A class is a way of grouping all the variables and functions relating to a specific object in one place. If you read 	that sentence and went <em>Huh?</em> don't worry. I found that Object Oriented Programming and dealing with classes to be one of the more difficult concepts to initially understand. I'm not sure why I had trouble with it but now that I've become comfortable with the idea and using 	classes it is without doubt something every web developer needs in their arsenal of abilities.<br />
<span id="more-6"></span><br />
Before we jump into my particular example it is important to ensure that we are all on the same page when it comes to OOP terminology.  The big 2:</p>
<ol>
<li><strong>Class - </strong>A class is the framework template for your <em>thing</em> (object).  That is, it is the template from which all objects will be built.  Classes contain two main parts:
<ul>
<li><strong>Variables/Attributes/Properties:</strong> The variables describe characteristics shared by all objects.  Take dogs for example.  How would you describe your dog (or a friend's) to someone else?You would probably let them know its name, size, gender, and color for starters.  These are all attributes or properties that every dog has, but they vary from dog to dog.</li>
<li><strong>Functions/Methods:</strong> A function describes actions that the object can perform.  Continuing our dog example, we would use functions such as <em>walk</em>, <em>bark</em>, and <em>sleep</em> in order to tell our virtual dog what to do.</li>
</ul>
<p>So a class might look something like this:</p>
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> Dog <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$gender</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$size</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$name</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$color</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> bark<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//bark stuff here</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> walk<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//walk stuff here</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> goToSleep<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//sleep stuff here</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></li>
<li><strong>Object:</strong> A particular instance of a class.  If the class was our generalized framework for what a dog may be, an object is a specific instance of that class.  For example we could have one object of our dog class, call it <em>dog1</em>, where the gender is male, the size is large, the name is Rex, and the color is black.  We could then have another object using the same framework, call it <em>dog2</em>, where the gender is male, the size is medium, the name is Champ, and the color is brown.  Both <em>dog1</em> and <em>dog2</em> are objects of the same class, but they hold different values.</li>
</ol>
<p>Hopefully that gives you a general understanding of what the difference between a class and an object are.  Now lets move on to a real-life example where I've used classes and objects to make my life a little easier: Generating large amounts of announcements.</p>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-create-a-class-in-php/">How to Create a Class in PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-create-a-class-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Connect to an Access Database Using PHP</title>
		<link>http://www.ryanprice.ca/how-to-connect-to-an-access-database-using-php/</link>
		<comments>http://www.ryanprice.ca/how-to-connect-to-an-access-database-using-php/#comments</comments>
		<pubDate>Fri, 04 May 2007 16:07:23 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/?p=5</guid>
		<description><![CDATA[Setting up the ODBC Connection Connecting to a MS Access Database using PHP is actually fairly straight-forward as long as you are using the right set-up. It is my understanding that you have to be either running a Windows server or be running PHP and Apache on your local windows system. The first thing you [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-connect-to-an-access-database-using-php/">How to Connect to an Access Database Using PHP</a></p>
]]></description>
			<content:encoded><![CDATA[<h3>Setting up the ODBC Connection</h3>
<p>Connecting to a MS Access Database using PHP is actually fairly straight-forward as long as you are using the right set-up.  It is my understanding that you have to be either running a Windows server or be <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">running PHP and Apache on your local windows system</a>.</p>
<p>The first thing you need to do is create what is called the <em>ODBC Connection</em>.  If you're using your local machine, like I am, or have access to your windows server then you can follow these steps:<br />
<span id="more-5"></span></p>
<ol>
<li>Open Administrative Tools: <strong>Start</strong> --&gt; <strong>Control Panel</strong> --&gt; <strong>Administrative Tools</strong></li>
<li>Open the Add Screen: Double-click <strong>Data Sources (ODBC)</strong> --&gt; click the <strong>Add</strong> tab --&gt; Select <strong>Microsoft Access Driver</strong> --&gt; <strong>Finish</strong></li>
<li>Select your database: Click <strong>Select</strong> and find your database --&gt; Name your Database (DSN) --&gt; <strong>OK</strong></li>
</ol>
<p>If you don't have direct access to the server you'll have to ask your administrator to do this for you.  Make sure you provide them with the path to the database you want set up as well as the name you want to use.</p>
<p>Our Access database is now ready to be connected to using PHP...</p>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-connect-to-an-access-database-using-php/">How to Connect to an Access Database Using PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-connect-to-an-access-database-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Recursively Delete a Directory Using PHP</title>
		<link>http://www.ryanprice.ca/how-to-empty-a-directory-using-php/</link>
		<comments>http://www.ryanprice.ca/how-to-empty-a-directory-using-php/#comments</comments>
		<pubDate>Fri, 27 Apr 2007 18:34:57 +0000</pubDate>
		<dc:creator>Ryan Price</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ryanprice.ca/work/?p=3</guid>
		<description><![CDATA[Introduction This tutorial will demonstrate how to use PHP to recursively delete a directory. That is, the directory and anything contained within it will be deleted. If you just need the function and are not interested in how it works its available below. Click "Plain Text" to see the code in a form it can [...]<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-empty-a-directory-using-php/">How to Recursively Delete a Directory Using PHP</a></p>
]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>This tutorial will demonstrate how to use PHP to recursively delete a directory.  That is, the directory and anything contained within it will be deleted.</p>
<p>If you just need the function and are not interested in how it works its available below.  Click "Plain Text" to see the code in a form it can be copied and pasted.  The function returns true on success and false on failure.  An explanation on what exactly is happening follows the code.<br />
<span id="more-3"></span></p>
<div class="igBar"><span id="lphp-10"><a href="#" onclick="javascript:showPlainTxt('php-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-10">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//This function will empty the directory it is sent.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> emptyDirectory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//first, lets make sure the user sent a directory.&nbsp; If they didn't, return &quot;false&quot;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the path has a slash at the end we remove it here</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span>,-<span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#FF0000;">'/'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$directory</span> = <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span>,<span style="color:#CC66CC;color:#800000;">0</span>,-<span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the path is not valid or is not a directory ...</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color:#000066;">file_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span> || !<a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... we return false and exit the function</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">FALSE</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... if the path is not readable</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/is_readable"><span style="color:#000066;">is_readable</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... we return false and exit the function</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">FALSE</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// ... else if the path is readable</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we open the directory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$handle</span> = <a href="http://www.php.net/opendir"><span style="color:#000066;">opendir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// and scan through the items inside</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">while</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$item</span> = <a href="http://www.php.net/readdir"><span style="color:#000066;">readdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$handle</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>!== <span style="color:#000000; font-weight:bold;">FALSE</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the filepointer is not the current directory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// or the parent directory</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$item</span> != <span style="color:#FF0000;">'.'</span> &amp;amp;&amp;amp; <span style="color:#0000FF;">$item</span> != <span style="color:#FF0000;">'..'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we build the new path to delete</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$path</span> = <span style="color:#0000FF;">$directory</span>.<span style="color:#FF0000;">'/'</span>.<span style="color:#0000FF;">$item</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the new path is a directory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color:#000066;">is_dir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$path</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we call this function with the new path</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; emptyDirectory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$path</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// if the new path is a file</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// we remove the file</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unlink"><span style="color:#000066;">unlink</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$path</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// close the directory</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/closedir"><span style="color:#000066;">closedir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$handle</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// try to delete the now empty directory</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/rmdir"><span style="color:#000066;">rmdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$directory</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// return false if not possible</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">FALSE</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// return success</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">TRUE</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now, let's dissect how this works...</p>
<p>This post is from <a href="http://www.ryanprice.ca">Ryan Price's blog</a>.<br/><br/><a href="http://www.ryanprice.ca/how-to-empty-a-directory-using-php/">How to Recursively Delete a Directory Using PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanprice.ca/how-to-empty-a-directory-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
