<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.7" -->
<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/"
	>

<channel>
	<title>Optimus Pete</title>
	<link>http://tech.petegraham.co.uk</link>
	<description>yes i love technology</description>
	<pubDate>Thu, 28 Jun 2007 17:33:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.7</generator>
	<language>en</language>
			<item>
		<title>PHP monitor server log</title>
		<link>http://tech.petegraham.co.uk/2007/06/28/php-monitor-server-log/</link>
		<comments>http://tech.petegraham.co.uk/2007/06/28/php-monitor-server-log/#comments</comments>
		<pubDate>Thu, 28 Jun 2007 17:16:52 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>Uncategorized</category>

		<category>Website Development</category>

		<category>php</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/06/28/php-monitor-server-log/</guid>
		<description><![CDATA[PHP monitor server log
Occasionally you'll be working on a webserver and not have SSH access to it. Below is a simple script I've written that reads a server log (in this case the error log) and outputs a portion of it to a webpage.
PLAIN TEXT
PHP:




$no_lines = 25;


&#160;


$filename = $_SERVER&#91;'DOCUMENT_ROOT'&#93;."/../logs/error.log";


$handle = fopen&#40;$filename, "r"&#41;;


$contents = fread&#40;$handle, filesize&#40;$filename&#41;&#41;;


fclose&#40;$handle&#41;;


&#160;


$contents [...]]]></description>
			<content:encoded><![CDATA[<p>PHP monitor server log</p>
<p>Occasionally you'll be working on a webserver and not have SSH access to it. Below is a simple script I've written that reads a server log (in this case the error log) and outputs a portion of it to a webpage.</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:#0000FF;">$no_lines</span> = <span style="color:#CC66CC;color:#800000;">25</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:#0000FF;">$filename</span> = <span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'DOCUMENT_ROOT'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#FF0000;">"/../logs/error.log"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$handle</span> = <a href="http://www.php.net/fopen"><span style="color:#000066;">fopen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$filename</span>, <span style="color:#FF0000;">"r"</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;"><span style="color:#0000FF;">$contents</span> = <a href="http://www.php.net/fread"><span style="color:#000066;">fread</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$handle</span>, <a href="http://www.php.net/filesize"><span style="color:#000066;">filesize</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$filename</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;"><a href="http://www.php.net/fclose"><span style="color:#000066;">fclose</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-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;"><span style="color:#0000FF;">$contents</span> = <a href="http://www.php.net/trim"><span style="color:#000066;">trim</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$contents</span>, <span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\n</span>"</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;"><span style="color:#0000FF;">$contentsArr</span> = <a href="http://www.php.net/explode"><span style="color:#000066;">explode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\n</span>"</span>, <span style="color:#0000FF;">$contents</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;"><span style="color:#0000FF;">$size</span> = <a href="http://www.php.net/sizeof"><span style="color:#000066;">sizeof</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$contentsArr</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;"><span style="color:#0000FF;">$n</span> = <span style="color:#0000FF;">$size</span> - <span style="color:#0000FF;">$no_lines</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;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&lt;h1&gt;monitor log&lt;/h1&gt;</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:#FF0000;">"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"</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:#FF0000;">&lt;ol start=<span style="color:#000099; font-weight:bold;">\"</span>$n<span style="color:#000099; font-weight:bold;">\"</span>&gt;"</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:#616100;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$n</span>; <span style="color:#0000FF;">$n</span>&lt;<span style="color:#0000FF;">$size</span>; <span style="color:#0000FF;">$n</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;"><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;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; &nbsp; &lt;li&gt;"</span>.<span style="color:#0000FF;">$contentsArr</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF;">$n</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#FF0000;">"&lt;/li&gt;</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:#FF0000;">"</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>
<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;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;/ol&gt;</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:#FF0000;">"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Obviously in a production environment you'd want to add some sort of password protection to such a script.</p>
<p>/* Pete Graham */
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/06/28/php-monitor-server-log/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mailto Hyperlinks Stop Spam Bots!</title>
		<link>http://tech.petegraham.co.uk/2007/06/28/mailto-hyperlinks-stop-spam-bots/</link>
		<comments>http://tech.petegraham.co.uk/2007/06/28/mailto-hyperlinks-stop-spam-bots/#comments</comments>
		<pubDate>Thu, 28 Jun 2007 16:30:20 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>Uncategorized</category>

		<category>Website Development</category>

		<category>spam</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/06/28/mailto-hyperlinks-stop-spam-bots/</guid>
		<description><![CDATA[Everyone hates spam, I hate it even more than most people. If you put an email address on a website, as a mailto hyperlink, then it's likely that spam bots will find this address and start sending annoying emails.
One way to get around this is to use a clever technique which I discovered over at [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone hates spam, I hate it even more than most people. If you put an email address on a website, as a mailto hyperlink, then it's likely that spam bots will find this address and start sending annoying emails.</p>
<p>One way to get around this is to use a clever technique which I discovered over at <a href="http://www.spamspan.com">SpamSpan.com</a>. Instead of entering your email like a normal hyperlink use the code below:</p>
<div class="igBar"><span id="lhtml-4"><a href="#" onclick="javascript:showPlainTxt('html-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-4">
<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/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"spamspan"</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;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"u"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>pete.graham<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span> [at] <span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"d"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>domain-name.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&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;">(<span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"t"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Pete's Email Address<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></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: #000000; font-weight: bold;">&lt;/span&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>A nifty piece of Javascript is then used to convert this html into a normal mailto hyperlink. Spam bots don't have Javascript enabled so wont register the link. If a visitor to your site have Javascript disabled they will see the link in the form below:<br />
petegraham [at] domain-name.com (Pete's Email Address)</p>
<p><img id="image102" alt="Email Spam Bot" src="http://tech.petegraham.co.uk/wp-content/uploads/2007/06/spambot.png" /></p>
<p># Pete Graham
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/06/28/mailto-hyperlinks-stop-spam-bots/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Vim Key Mappings</title>
		<link>http://tech.petegraham.co.uk/2007/06/05/vim-key-mappings/</link>
		<comments>http://tech.petegraham.co.uk/2007/06/05/vim-key-mappings/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 15:50:38 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>vim</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/06/05/vim-key-mappings/</guid>
		<description><![CDATA[One of the things I always found awkward about Vim is stretching for the ESC key to get out of insert mode.
Here's a little trick that I like to add into my .vimrc file:
PLAIN TEXT
CODE:




map&#160; &#60;space&#62; i


imap &#60;S-space&#62; &#60;esc&#62; 






This will let you escape insert mode by pressing shift and space and enter insert mode [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I always found awkward about Vim is stretching for the ESC key to get out of insert mode.</p>
<p>Here's a little trick that I like to add into my .vimrc file:</p>
<div class="igBar"><span id="lcode-6"><a href="#" onclick="javascript:showPlainTxt('code-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-6">
<div class="code">
<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;">map&nbsp; &lt;space&gt; i</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">imap &lt;S-space&gt; &lt;esc&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This will let you escape insert mode by pressing shift and space and enter insert mode by pressing space.</p>
<p>/* Pete Graham */
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/06/05/vim-key-mappings/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IE7 Clicky Sounds Do my Nut in!</title>
		<link>http://tech.petegraham.co.uk/2007/06/05/ie7-clicky-sounds-do-my-nut-in/</link>
		<comments>http://tech.petegraham.co.uk/2007/06/05/ie7-clicky-sounds-do-my-nut-in/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 15:36:46 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>Uncategorized</category>

		<category>Internet Explorer</category>

		<category>Website Development</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/06/05/ie7-clicky-sounds-do-my-nut-in/</guid>
		<description><![CDATA[I'm not a fan of applications that use sounds effects, one of the first things I do when configuring a new PC is to set the Windows Sound scheme to 'No Sounds'. IE7 has the hugely annoying feature where a click sound is made when you click a link with the middle mouse button (this [...]]]></description>
			<content:encoded><![CDATA[<p>I'm not a fan of applications that use sounds effects, one of the first things I do when configuring a new PC is to set the Windows Sound scheme to 'No Sounds'. IE7 has the hugely annoying feature where a click sound is made when you click a link with the middle mouse button (this opens the link in a new tab).</p>
<p>My preferred browser of choice is Firefox but working in Web Development I often need to test website across a range of different browser, hence the need to use IE7. So far I have found no way of disabling this infuriating sound! Tortoise SVN is another offending program, there's nothing worst than having listening to some music interrupted with the 'Conflicting Files' sound!</p>
<p>If anyone finds any way of disabling the IE7 noise let me know and you will be my Hero for a whole day!</p>
<p># Pete Graham
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/06/05/ie7-clicky-sounds-do-my-nut-in/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP: File Downloads HTTP Headers</title>
		<link>http://tech.petegraham.co.uk/2007/05/16/php-file-downloads-http-headers/</link>
		<comments>http://tech.petegraham.co.uk/2007/05/16/php-file-downloads-http-headers/#comments</comments>
		<pubDate>Wed, 16 May 2007 10:53:47 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>Website Development</category>

		<category>php</category>

		<category>regular expressions</category>

		<category>programming</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/16/php-file-downloads-http-headers/</guid>
		<description><![CDATA[In PHP you can provide file downloads by using a PHP page to “pass through” the file. Of course you could just link to the actual file, however this technique means your file can kept outside of your website root. Another advantage is you can integrate this system into a PHP based user/password system easily.
Now [...]]]></description>
			<content:encoded><![CDATA[<p>In PHP you can provide file downloads by using a PHP page to “pass through” the file. Of course you could just link to the actual file, however this technique means your file can kept outside of your website root. Another advantage is you can integrate this system into a PHP based user/password system easily.</p>
<p>Now this technique is fairly straightforward, but you need to make sure you get the HTTP Headers correct for it to run smoothly. Here’s the code:</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:#0000FF;">$file</span> = <span style="color:#FF0000;">"/path/to/file.txt"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$file_extension</span> = <a href="http://www.php.net/strtolower"><span style="color:#000066;">strtolower</span></a><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><a href="http://www.php.net/strrchr"><span style="color:#000066;">strrchr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$basename</span>,<span style="color:#FF0000;">"."</span><span style="color:#006600; font-weight:bold;">&#41;</span>,<span style="color:#CC66CC;color:#800000;">1</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;</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;">//This will set the Content-Type to the appropriate setting for 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;"><span style="color:#616100;">switch</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file_extension</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;"><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;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"htm"</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"xhtml"</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:#616100;">case</span> <span style="color:#FF0000;">"txt"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"html"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"text/html"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"pdf"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"application/pdf"</span>; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"doc"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"application/msword"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"exe"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"application/octet-stream"</span>; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"zip"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"application/zip"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"xls"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"application/vnd.ms-excel"</span>; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"ppt"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"application/vnd.ms-powerpoint"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"gif"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"image/gif"</span>; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"png"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"image/png"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"jpeg"</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"jpg"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"image/jpeg"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"mp3"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"audio/mpeg"</span>; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"wav"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"audio/x-wav"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"mpeg"</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"mpg"</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:#616100;">case</span> <span style="color:#FF0000;">"mpe"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"video/mpeg"</span>; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">case</span> <span style="color:#FF0000;">"mov"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"video/quicktime"</span>; <span style="color:#616100;">break</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:#616100;">case</span> <span style="color:#FF0000;">"avi"</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"video/x-msvideo"</span>; <span style="color:#616100;">break</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;">default</span>: <span style="color:#0000FF;">$ctype</span>=<span style="color:#FF0000;">"application/force-download"</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:#FF9933; font-style:italic;">//Begin writing headers</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Pragma: public"</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;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Expires: 0"</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;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Cache-Control: must-revalidate, post-check=0, pre-check=0"</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;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Cache-Control: public"</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;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-Description: File Transfer"</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;"><span style="color:#FF9933; font-style:italic;">//Use the switch-generated Content-Type</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-Type: $ctype"</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;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-Length: "</span>.<a href="http://www.php.net/filesize"><span style="color:#000066;">filesize</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file</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;</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:#FF9933; font-style:italic;">// regex stops download prompt for browser associated types</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/preg_match"><span style="color:#000066;">preg_match</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/(htm|xhtml|txt|html|gif|png|jpeg|jpg)/'</span>, <span style="color:#0000FF;">$file_extension</span>, <span style="color:#0000FF;">$matches</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;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-Disposition: attachment; filename=<span style="color:#000099; font-weight:bold;">\"</span>"</span>.<a href="http://www.php.net/basename"><span style="color:#000066;">basename</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$filename</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\"</span>;"</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;"><span style="color:#FF9933; font-style:italic;">// output the file</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/readfile"><span style="color:#000066;">readfile</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"$file"</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;"><a href="http://www.php.net/exit"><span style="color:#000066;">exit</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I will be writing a follow up article in the future that shows how this technique can be improvement using Apache's mod-rewrite to provide cleaner URLs for file downloads.</p>
<p><strong>Note:</strong> The regular expression on line 42 will make files normally associated with the browser (images, webpages, etc) open inside the browser. If you want to get the “open/save” download prompt for all types of files then comment out this line.</p>
<p><strong>Note:</strong> Make sure you use: “Content-Type: image/jpeg” for JPGs, IE doesn’t seems to like “Content-Type: image/jpg”</p>
<p># Pete Graham
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/05/16/php-file-downloads-http-headers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Away with Applications: The Death of Desktop</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/away-with-applications-the-death-of-desktop/</link>
		<comments>http://tech.petegraham.co.uk/2007/05/15/away-with-applications-the-death-of-desktop/#comments</comments>
		<pubDate>Tue, 15 May 2007 15:09:39 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>Tech</category>

		<category>usability</category>

		<category>videos</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/away-with-applications-the-death-of-desktop/</guid>
		<description><![CDATA[There is a great talk that went up on Google Videos earlier this month called Away with Applications: The Death of Deskop. In it the speaker, Aza Raskin points out that no work is carried out actually using the computers desktop. He also points out the failing of desktop applications, that you frequently need to [...]]]></description>
			<content:encoded><![CDATA[<p>There is a great talk that went up on Google Videos earlier this month called <a target="_blank" href="http://video.google.com/videoplay?docid=-6856727143023456694">Away with Applications: The Death of Deskop</a>. In it the speaker, Aza Raskin points out that no work is carried out actually using the computers desktop. He also points out the failing of desktop applications, that you frequently need to switch between applications, moving content, to achieve even relatively simple tasks.</p>
<p>I think his points are particularly relevant as we move into an age where many traditional desktop apps are being converted to web applications. I see an increasing trend in web applications of people trying to recreate desktop applications like interfaces in a browser-based setting. Aza urges us to rethink what we know about computer interfaces and to come up with exciting and innovative alternatives.</p>
<p>Traditional applications have had more and more functionality added to them to an extent that they have become <em>“a portmanteau of all possible features”</em>, again it is worrying that many of today’s successful web apps could suffer the same fate. The speaker encourages open APIs and Mash-ups as an alternative and a may to combine applications without having to switch between multiple programs/services.</p>
<p>One of the most interesting parts of the talk for me is when the speaker demos some systems that he's been developing himself, one is a command-line interface for launching applications that uses almost real language commands and auto-complete. The other is an interesting zoomable desktop, which is much more work orientated than the traditional model, it also centres around the concept of <em>“content as content”</em>.</p>
<p>At nearly an hour and a half the video is quite long but I found it extremely interesting, the speaker also looks a bit like Rick Moranis of <em>“Honey I shrunk the kids”</em> fame, which has got to be a good thing.</p>
<p># Pete Graham
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/05/15/away-with-applications-the-death-of-desktop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP: Get First Index in Associative Array</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/</link>
		<comments>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comments</comments>
		<pubDate>Tue, 15 May 2007 14:07:43 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>Website Development</category>

		<category>php</category>

		<category>programming</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/</guid>
		<description><![CDATA[The other day I was programming in PHP and needed to get the first index in an associative array. There doesn’t appear to be a built in function to deal with this so I wrote my own.
PLAIN TEXT
PHP:




function getArrayFirstIndex&#40;$arr&#41;


&#123;


foreach &#40;$arr as $key =&#62; $value&#41;


return $key;


&#125; 






Here's a bit of code you can test it on:
PLAIN [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was programming in PHP and needed to get the first index in an associative array. There doesn’t appear to be a built in function to deal with this so I wrote my own.</p>
<div class="igBar"><span id="lphp-11"><a href="#" onclick="javascript:showPlainTxt('php-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-11">
<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;">function</span> getArrayFirstIndex<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$arr</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;"><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;"><span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$arr</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$key</span> =&gt; <span style="color:#0000FF;">$value</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;"><span style="color:#616100;">return</span> <span style="color:#0000FF;">$key</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>
</ol>
</div>
</div>
</div>
<p></p>
<p>Here's a bit of code you can test it on:</p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-12">
<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:#0000FF;">$arr</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'banana'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">"yellow"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$arr</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'apple'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">"apple"</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:#0000FF;">$arr</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'orange'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">"orange"</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:#0000FF;">$first_index</span> = getArrayFirstIndex<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$arr</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;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"first index ="</span>.<span style="color:#0000FF;">$first_index</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The above code will output 'first index = banana'.</p>
<p>/* Pete Graham */
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JS: Execute JavaScript on Page Load</title>
		<link>http://tech.petegraham.co.uk/2007/05/14/js-execute-javascript-on-page-load/</link>
		<comments>http://tech.petegraham.co.uk/2007/05/14/js-execute-javascript-on-page-load/#comments</comments>
		<pubDate>Mon, 14 May 2007 10:47:11 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>javascript</category>

		<category>Website Development</category>

		<category>programming</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/14/js-execute-javascript-on-page-load/</guid>
		<description><![CDATA[Recently I’ve been making an effort to improve my JavaScript skills, I’m not a JavaScript-Jedi yet but I have been picking up a few, tips, tricks and techniques.
One thing that I find extremely useful is using an init function to call other functions when the page has loaded. I have been using the nifty function [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I’ve been making an effort to improve my JavaScript skills, I’m not a JavaScript-Jedi yet but I have been picking up a few, tips, tricks and techniques.</p>
<p>One thing that I find extremely useful is using an init function to call other functions when the page has loaded. I have been using the nifty function below:</p>
<div class="igBar"><span id="ljavascript-16"><a href="#" onclick="javascript:showPlainTxt('javascript-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-16">
<div class="javascript">
<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: #003366; font-weight: bold;">function</span> WindowOnload<span style="color: #66cc66;">&#40;</span>f<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#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;"><span style="color: #003366; font-weight: bold;">var</span> prev=window.<span style="color: #000066;">onload</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">window.<span style="color: #000066;">onload</span>=<span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>prev<span style="color: #66cc66;">&#41;</span>prev<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; f<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#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;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I save this function in a file called init.js which is then included in my HTML pages using:</p>
<div class="igBar"><span id="lhtml-17"><a href="#" onclick="javascript:showPlainTxt('html-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-17">
<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> xsrc=<span style="color: #ff0000;">"/js/init.js"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/javascript"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><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>Functions can then be initialised by including the following in the HTML:</p>
<div class="igBar"><span id="ljavascript-18"><a href="#" onclick="javascript:showPlainTxt('javascript-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-18">
<div class="javascript">
<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;">&lt;script language=<span style="color: #3366CC;">"JavaScript"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;!--</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;">WindowOnload<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#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;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">a_function<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Sdelete_date'</span><span style="color: #66cc66;">&#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;"><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#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;">WindowOnload<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#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;">another_function<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a_parameter'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#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;"><span style="color: #009900; font-style: italic;">//--&gt;</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;">&lt;/script&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The above code is inline JavaScript which is often seen as being naughty, obviously you can save the same code to a separate file and include that instead.</p>
<p>I originally saw this technique <a href="http://blog.firetree.net/2005/07/17/javascript-onload/">here</a>. Alternative JS <a href="http://simonwillison.net/2004/May/26/addLoadEvent/">initialisation scripts</a> are available but so far this one has worked well for me, so I’ll be sticking with it.</p>
<p># Pete Graham
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/05/14/js-execute-javascript-on-page-load/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Vim: Search and Replace, Insert new line</title>
		<link>http://tech.petegraham.co.uk/2007/05/03/vim-search-and-replace-insert-new-line/</link>
		<comments>http://tech.petegraham.co.uk/2007/05/03/vim-search-and-replace-insert-new-line/#comments</comments>
		<pubDate>Thu, 03 May 2007 11:36:15 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>regex</category>

		<category>regular expressions</category>

		<category>vim</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/03/vim-search-and-replace-insert-new-line/</guid>
		<description><![CDATA[Vim has some really useful commands, especially search and replace ones. Unfortunately I'm always forgetting the finer details of how to use them so here's an example:
PLAIN TEXT
CODE:




:%s/$/\rthis is a new line 






To break down whats happening above:

: switches Vim into command mode
% means we're going to apply this command to every line in our [...]]]></description>
			<content:encoded><![CDATA[<p>Vim has some really useful commands, especially search and replace ones. Unfortunately I'm always forgetting the finer details of how to use them so here's an example:</p>
<div class="igBar"><span id="lcode-20"><a href="#" onclick="javascript:showPlainTxt('code-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-20">
<div class="code">
<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;">:%s/$/\rthis is a new line </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>To break down whats happening above:</p>
<ul>
<li><strong>:</strong> switches Vim into command mode</li>
<li><strong>%</strong> means we're going to apply this command to every line in our file</li>
<li><span style="font-weight: bold">s</span> means we're using the substitute command. The format of the command is <span style="font-weight: bold">s/search/replacement</span>, 'search' can be a regular expression</li>
<li><span style="font-weight: bold">$</span> tells vim to search for the end of the line</li>
<li><span style="font-weight: bold">\rthis is a new line</span> tells vim to replace with a new line character, and to put the text "this is a new line" on that line.</li>
</ul>
<p><span style="font-weight: bold">NOTE:</span> \r is used as the new line character when vim is using DOS file format, to find out which file format you are using type <span style="font-weight: bold">:set ff?</span> You can find out more about Vim file formats <a target="_blank" href="http://www.vim.org/tips/tip.php?tip_id=145)">here</a>.</p>
<p>#Pete Graham
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/05/03/vim-search-and-replace-insert-new-line/feed/</wfw:commentRss>
		</item>
		<item>
		<title>It’s internet with a small ‘i’ now</title>
		<link>http://tech.petegraham.co.uk/2007/04/30/it%e2%80%99s-internet-with-a-small-%e2%80%98i%e2%80%99-now/</link>
		<comments>http://tech.petegraham.co.uk/2007/04/30/it%e2%80%99s-internet-with-a-small-%e2%80%98i%e2%80%99-now/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 10:50:23 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
		
		<category>Tech</category>

		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/04/30/it%e2%80%99s-internet-with-a-small-%e2%80%98i%e2%80%99-now/</guid>
		<description><![CDATA[When I was doing my Computer Science degree our lectures used to make a big deal about making sure you spell Internet with a capital ‘I’, because it’s important and it’s the name of a thing. Apparently it’s now been decided that it should be spelt with a lowercase ‘i’, I wish bloody linguists would [...]]]></description>
			<content:encoded><![CDATA[<p>When I was doing my Computer Science degree our lectures used to make a big deal about making sure you spell Internet with a capital ‘I’, because it’s important and it’s the name of a thing. Apparently it’s now been decided that it should be spelt with a lowercase ‘i’, I wish bloody linguists would make their minds up!</p>
<p># Pete Graham
</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.petegraham.co.uk/2007/04/30/it%e2%80%99s-internet-with-a-small-%e2%80%98i%e2%80%99-now/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
