<?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>Random Web Tools &#187; Code</title>
	<atom:link href="http://www.randomtools.net/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.randomtools.net</link>
	<description>Advice and tools from a young web developer</description>
	<lastBuildDate>Mon, 16 Aug 2010 06:16:11 +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 Hide Android WebView Highlight Border (or change it&#8217;s color)</title>
		<link>http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html</link>
		<comments>http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html#comments</comments>
		<pubDate>Sat, 27 Feb 2010 23:20:37 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[How To's]]></category>

		<guid isPermaLink="false">http://www.randomtools.net/?p=142</guid>
		<description><![CDATA[Here&#39;s one that had me at a loss for a long time that I just figured out. You can easily remove the highlight border (the border that comes up when an element is focused) or change it&#39;s color in a WebView with CSS! The WebKit-specific property &#34;-webkit-tap-highlight-color&#34; is what you&#39;re looking for. The following line [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#39;s one that had me at a loss for a long time that I just figured out. You can easily remove the highlight border (the border that comes up when an element is focused) or change it&#39;s color in a WebView with CSS! The WebKit-specific property &quot;-webkit-tap-highlight-color&quot; is what you&#39;re looking for.</p>
<p>The following line will disable it on a page completely:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span>
	-webkit-tap-highlight-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>	
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>rgba() is just like rgb(), but it takes a 4th parameter for opacity. It&#39;s my belief that this would probably work for iPhone WebView&#39;s as well, since both Chrome and Safari are based off of WebKit.</p>
<div style="width: 300px; height: 300px;"><div style="width: 300px; height: 250px; margin: 3px;"><script type="text/javascript"><!--
google_ad_client = "pub-1936238606905173";
google_ad_slot = "4013486594";
google_ad_width = 300;
google_ad_height = 250;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div></div>
<div class='bookmarkify'><a name='bookmarkify'></a><div class='title' title='Use these links to share this page with others'>Bookmark this page</div><div class='linkbuttons'><a href='http://del.icio.us/post?url=http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html&amp;title=How to Hide Android WebView Highlight Border (or change it&#8217;s color)' title='Save to del.icio.us' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png' style='width:16px; height:16px;' alt='[del.icio.us] ' /></a> <a href='http://digg.com/submit?phase=2&amp;url=http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html&amp;title=How to Hide Android WebView Highlight Border (or change it&#8217;s color)' title='Digg It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png' style='width:16px; height:16px;' alt='[Digg] ' /></a> <a href='http://www.facebook.com/share.php?u=http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html' title='Save to Facebook' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png' style='width:16px; height:16px;' alt='[Facebook] ' /></a> <a href='http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html&amp;title=How to Hide Android WebView Highlight Border (or change it&#8217;s color)' title='Save to Google Bookmarks' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png' style='width:16px; height:16px;' alt='[Google] ' /></a> <a href='http://reddit.com/submit?url=http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html&amp;title=How to Hide Android WebView Highlight Border (or change it&#8217;s color)' title='Reddit' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png' style='width:16px; height:16px;' alt='[Reddit] ' /></a> <a href='http://slashdot.org/bookmark.pl?url=http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html&amp;title=How to Hide Android WebView Highlight Border (or change it&#8217;s color)' title='Slashdot It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png' style='width:16px; height:16px;' alt='[Slashdot] ' /></a> <a href='http://www.stumbleupon.com/submit?url=http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html&amp;title=How to Hide Android WebView Highlight Border (or change it&#8217;s color)' title='Stumble It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png' style='width:16px; height:16px;' alt='[StumbleUpon] ' /></a> </div></div>]]></content:encoded>
			<wfw:commentRss>http://www.randomtools.net/how-to-hide-android-webview-highlight-border-or-change-its-color-142.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP RSS Parser &#8211; RSS Reader Class for PHP</title>
		<link>http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html</link>
		<comments>http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html#comments</comments>
		<pubDate>Mon, 22 Feb 2010 05:49:24 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.randomtools.net/?p=133</guid>
		<description><![CDATA[Just had to create a quick RSS parser for PHP and thought I&#39;d post my solution. The implementation and class follows. &#60;?php $rss = new RSSReader('http://news.google.com/?output=rss'); while ($rss -&#62; hasNext()) print_r($rss -&#62; next()); ?&#62; &#60;?php class RSSReader { var $xml = null; var $pos = 0; var $count = 0; function __construct($feed_url) { $this -&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Just had to create a quick RSS parser for PHP and thought I&#39;d post my solution. The implementation and class follows.</p>
<pre class="brush: php">&lt;?php
$rss = new RSSReader('http://news.google.com/?output=rss');
while ($rss -&gt; hasNext())
	print_r($rss -&gt; next());
?&gt;</pre>
<div style="width: 300px; height: 300px; clear: both;"><div style="width: 300px; height: 250px; margin: 3px;"><script type="text/javascript"><!--
google_ad_client = "pub-1936238606905173";
google_ad_slot = "4013486594";
google_ad_width = 300;
google_ad_height = 250;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div></div>
<pre class="brush: php">&lt;?php
class RSSReader {
	var $xml = null;
	var $pos = 0;
	var $count = 0;

	function __construct($feed_url) {
		$this -&gt; load_url($feed_url);
	}

	function load_url($feed_url) {
		$this -&gt; load_string(file_get_contents($feed_url));
	}

	function load_string($feed_string) {
		$this -&gt; xml = simplexml_load_string(str_replace('content:encoded', 'content_encoded', $feed_string));
		$this -&gt; pos = 0;
		$this -&gt; count = count($this -&gt; xml -&gt; channel -&gt; item);
	}

	function get_title() {
		return $this -&gt; xml -&gt; channel -&gt; title;
	}

	function get_link() {
		return $this -&gt; xml -&gt; channel -&gt; link;
	}

	function get_pubdate() {
		return $this -&gt; xml -&gt; channel -&gt; pubdate;
	}

	function hasNext() {
		return $this -&gt; count &gt; $this -&gt; pos;
	}

	function next() {
		$obj = $this -&gt; xml -&gt; channel -&gt; item[$this -&gt; pos++];
		return array(
			'title' =&gt; (string) $obj -&gt; title,
			'link' =&gt; (string) $obj -&gt; link,
			'description' =&gt; (string) $obj -&gt; description,
			'content' =&gt; (string) $obj -&gt; content_encoded,
			'pubDate' =&gt; strtotime($obj -&gt; pubDate),
		);
	}
}
?&gt;</pre>
<div class='bookmarkify'><a name='bookmarkify'></a><div class='title' title='Use these links to share this page with others'>Bookmark this page</div><div class='linkbuttons'><a href='http://del.icio.us/post?url=http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html&amp;title=PHP RSS Parser &#8211; RSS Reader Class for PHP' title='Save to del.icio.us' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png' style='width:16px; height:16px;' alt='[del.icio.us] ' /></a> <a href='http://digg.com/submit?phase=2&amp;url=http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html&amp;title=PHP RSS Parser &#8211; RSS Reader Class for PHP' title='Digg It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png' style='width:16px; height:16px;' alt='[Digg] ' /></a> <a href='http://www.facebook.com/share.php?u=http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html' title='Save to Facebook' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png' style='width:16px; height:16px;' alt='[Facebook] ' /></a> <a href='http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html&amp;title=PHP RSS Parser &#8211; RSS Reader Class for PHP' title='Save to Google Bookmarks' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png' style='width:16px; height:16px;' alt='[Google] ' /></a> <a href='http://reddit.com/submit?url=http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html&amp;title=PHP RSS Parser &#8211; RSS Reader Class for PHP' title='Reddit' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png' style='width:16px; height:16px;' alt='[Reddit] ' /></a> <a href='http://slashdot.org/bookmark.pl?url=http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html&amp;title=PHP RSS Parser &#8211; RSS Reader Class for PHP' title='Slashdot It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png' style='width:16px; height:16px;' alt='[Slashdot] ' /></a> <a href='http://www.stumbleupon.com/submit?url=http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html&amp;title=PHP RSS Parser &#8211; RSS Reader Class for PHP' title='Stumble It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png' style='width:16px; height:16px;' alt='[StumbleUpon] ' /></a> </div></div>]]></content:encoded>
			<wfw:commentRss>http://www.randomtools.net/php-rss-parser-rss-reader-class-for-php-133.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To Convert Large XML Files to CSV</title>
		<link>http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html</link>
		<comments>http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html#comments</comments>
		<pubDate>Fri, 02 Oct 2009 03:45:24 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[How To's]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.randomtools.net/?p=78</guid>
		<description><![CDATA[&#160;I usually struggle with convert very large XML files to other formats just because they are in a dynamic format and most programs you find run out of memory before properly parsing them.&#160;Well, I&#39;m happy to say, I found a FAST and EASY solution. Of course this will work for small files as well as [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 300px; height: 250px; margin: 5px;"><div style="width: 300px; height: 250px; margin: 3px;"><script type="text/javascript"><!--
google_ad_client = "pub-1936238606905173";
google_ad_slot = "4013486594";
google_ad_width = 300;
google_ad_height = 250;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div></div>
<p>&nbsp;I usually struggle with convert very large XML files to other formats just because they are in a dynamic format and most programs you find run out of memory before properly parsing them.&nbsp;Well, I&#39;m happy to say, I found a FAST and EASY solution. Of course this will work for small files as well as big files.</p>
<p>You&#39;ll want to grab a copy of the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2FB55371-C94E-4373-B0E9-DB4816552E41&amp;displaylang=en" rel="nofollow">msxsl</a> command line utility from Microsoft.</p>
<p>After you&#39;ve got that, you&#39;ll need to setup a XSL file to tell the program how to format your file. If you&#39;re unfamiliar with XSL, you can familiarize yourself <a href="http://www.w3schools.com/xsl/">here</a>.</p>
<p>After you&#39;ve got your XSL file created, it&#39;s a simple command line entry:</p>
<pre class="brush: vb">msxsl xml_file.xml xsl_file.xsl -o output_file.csv</pre>
<p>The following is a sample XML and XSL file that I used.</p>
<p>XML File:</p>
<pre class="brush: xml:showcolumns"><catalog>
	<content>
		<contentid>772500</contentid>
		<createdate>Tue, 20 Jan 2009 16:28:08 CST</createdate>
		<lastupdatedate>Tue, 20 Jan 2009 16:51:01 CST</lastupdatedate>

		<description>
		<artist>
			<id>61951</id>
			<name>The Hills Season 1</name>
		</artist>
	</description></content>
	<content>
		<contentid>773000</contentid>
		<createdate>Tue, 20 Jan 2009 16:28:08 CST</createdate>
		<lastupdatedate>Tue, 20 Jan 2009 16:53:54 CST</lastupdatedate>

		<description>
		<artist>
			<id>61926</id>
			<name>Hogan Knows Best Season 2</name>
		</artist>
	</description></content>
	<content>
		<contentid>775500</contentid>
		<createdate>Thu, 22 Jan 2009 14:49:12 CST</createdate>
		<lastupdatedate>Thu, 22 Jan 2009 14:51:35 CST</lastupdatedate>

		<description>
		<artist>
			<id>62068</id>
			<name>Carlos Mencia 2007</name>
		</artist>
		<category>
			<id>1402</id>
			<name>Comedy Central</name>
		</category>
	</description></content>
</catalog></pre>
<p>XSL File (Creates tab-delimited file)</p>
<pre class="brush: xml"><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<xsl:for-each select="catalog/content">
			<xsl:value-of select="title"><xsl:text>	</xsl:text><xsl:value-of select="artist/name"><xsl:text>
</xsl:text>
		</xsl:value-of></xsl:value-of></xsl:for-each>
	</xsl:template>
</xsl:stylesheet></pre>
<div class='bookmarkify'><a name='bookmarkify'></a><div class='title' title='Use these links to share this page with others'>Bookmark this page</div><div class='linkbuttons'><a href='http://del.icio.us/post?url=http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html&amp;title=How To Convert Large XML Files to CSV' title='Save to del.icio.us' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png' style='width:16px; height:16px;' alt='[del.icio.us] ' /></a> <a href='http://digg.com/submit?phase=2&amp;url=http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html&amp;title=How To Convert Large XML Files to CSV' title='Digg It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png' style='width:16px; height:16px;' alt='[Digg] ' /></a> <a href='http://www.facebook.com/share.php?u=http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html' title='Save to Facebook' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png' style='width:16px; height:16px;' alt='[Facebook] ' /></a> <a href='http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html&amp;title=How To Convert Large XML Files to CSV' title='Save to Google Bookmarks' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png' style='width:16px; height:16px;' alt='[Google] ' /></a> <a href='http://reddit.com/submit?url=http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html&amp;title=How To Convert Large XML Files to CSV' title='Reddit' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png' style='width:16px; height:16px;' alt='[Reddit] ' /></a> <a href='http://slashdot.org/bookmark.pl?url=http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html&amp;title=How To Convert Large XML Files to CSV' title='Slashdot It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png' style='width:16px; height:16px;' alt='[Slashdot] ' /></a> <a href='http://www.stumbleupon.com/submit?url=http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html&amp;title=How To Convert Large XML Files to CSV' title='Stumble It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png' style='width:16px; height:16px;' alt='[StumbleUpon] ' /></a> </div></div>]]></content:encoded>
			<wfw:commentRss>http://www.randomtools.net/how-to-convert-large-xml-files-to-csv-78.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP File-System Cache</title>
		<link>http://www.randomtools.net/php-file-system-cache-58.html</link>
		<comments>http://www.randomtools.net/php-file-system-cache-58.html#comments</comments>
		<pubDate>Tue, 25 Aug 2009 00:22:44 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web Tools]]></category>

		<guid isPermaLink="false">http://www.randomtools.net/?p=58</guid>
		<description><![CDATA[I&#8217;m just sharing a couple of functions I created a while back to cache some resource-intensive processed dada for quick and easy access. This is pretty ideal for large amounts of data and it&#8217;s very simple to set up. The beauty of this is that you can store just about any data type &#8211; it [...]]]></description>
			<content:encoded><![CDATA[<div style="width: 300px; height: 250px; margin: 5px; float: right;"><div style="width: 300px; height: 250px; margin: 3px;"><script type="text/javascript"><!--
google_ad_client = "pub-1936238606905173";
google_ad_slot = "4013486594";
google_ad_width = 300;
google_ad_height = 250;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div></div>
<p>I&#8217;m just sharing a couple of functions I created a while back to cache some resource-intensive processed dada for quick and easy access. This is pretty ideal for large amounts of data and it&#8217;s very simple to set up. The beauty of this is that you can store just about any data type &#8211; it doesn&#8217;t have to be a string.</p>
<p>Just setup the cache directory to have proper read/write permissions (preferably in a non-accessible from web directory). Then use the two functions.</p>
<p style="clear: both;"><strong>Example usage:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// The 2nd argument, $hours is how long to retain data before getting new</span>
<span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> get_cache<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TEST_KEY'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$contents</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// This is where you'd get data from an API, DB or whatever</span>
	<span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Just some example contents'</span><span style="color: #339933;">;</span>
	set_cache<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TEST_KEY'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$contents</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$contents</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Code:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CACHE_DIR'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Include trailing slash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> get_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hours</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> CACHE_DIR <span style="color: #339933;">.</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.cache'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$hours</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> set_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> CACHE_DIR <span style="color: #339933;">.</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.cache'</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div class='bookmarkify'><a name='bookmarkify'></a><div class='title' title='Use these links to share this page with others'>Bookmark this page</div><div class='linkbuttons'><a href='http://del.icio.us/post?url=http://www.randomtools.net/php-file-system-cache-58.html&amp;title=PHP File-System Cache' title='Save to del.icio.us' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png' style='width:16px; height:16px;' alt='[del.icio.us] ' /></a> <a href='http://digg.com/submit?phase=2&amp;url=http://www.randomtools.net/php-file-system-cache-58.html&amp;title=PHP File-System Cache' title='Digg It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png' style='width:16px; height:16px;' alt='[Digg] ' /></a> <a href='http://www.facebook.com/share.php?u=http://www.randomtools.net/php-file-system-cache-58.html' title='Save to Facebook' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png' style='width:16px; height:16px;' alt='[Facebook] ' /></a> <a href='http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.randomtools.net/php-file-system-cache-58.html&amp;title=PHP File-System Cache' title='Save to Google Bookmarks' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png' style='width:16px; height:16px;' alt='[Google] ' /></a> <a href='http://reddit.com/submit?url=http://www.randomtools.net/php-file-system-cache-58.html&amp;title=PHP File-System Cache' title='Reddit' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png' style='width:16px; height:16px;' alt='[Reddit] ' /></a> <a href='http://slashdot.org/bookmark.pl?url=http://www.randomtools.net/php-file-system-cache-58.html&amp;title=PHP File-System Cache' title='Slashdot It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png' style='width:16px; height:16px;' alt='[Slashdot] ' /></a> <a href='http://www.stumbleupon.com/submit?url=http://www.randomtools.net/php-file-system-cache-58.html&amp;title=PHP File-System Cache' title='Stumble It!' onclick='target="_blank";' rel='nofollow'><img src='http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png' style='width:16px; height:16px;' alt='[StumbleUpon] ' /></a> </div></div>]]></content:encoded>
			<wfw:commentRss>http://www.randomtools.net/php-file-system-cache-58.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
