<?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>Michael Doyle &#124; Blog &#187; PHP</title>
	<atom:link href="http://michaeldoyle.eu/blog/category/server-side-scripting/php/feed" rel="self" type="application/rss+xml" />
	<link>http://michaeldoyle.eu/blog</link>
	<description>Well, I&#039;m not sure whether to call this a blog or a sideblog. Either way, it&#039;s my personal, never-ending, post-it note, so that when I learn something interesting, it&#039;ll find its way here.</description>
	<lastBuildDate>Mon, 30 Nov 2009 01:44:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP &#8211; How to Debug In PHP</title>
		<link>http://michaeldoyle.eu/blog/server-side-scripting/php/php-how-to-debug-in-php</link>
		<comments>http://michaeldoyle.eu/blog/server-side-scripting/php/php-how-to-debug-in-php#comments</comments>
		<pubDate>Tue, 06 Oct 2009 12:35:28 +0000</pubDate>
		<dc:creator>Michael Doyle</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[var_dump()]]></category>

		<guid isPermaLink="false">http://michaeldoyle.eu/blog/?p=382</guid>
		<description><![CDATA[Carsonified has a good blog entry about how to debug in PHP. It outlines the 4 php error types, using var_dump() and recommends some tools to help with debugging.
http://carsonified.com/blog/dev/how-to-debug-in-php/


No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://carsonified.com/blog/dev/how-to-debug-in-php/" target="_blank">Carsonified</a> has a good blog entry about how to debug in PHP. It outlines the 4 php error types, using var_dump() and recommends some tools to help with debugging.</p>
<p><a href="http://carsonified.com/blog/dev/how-to-debug-in-php/" target="_blank">http://carsonified.com/blog/dev/how-to-debug-in-php/</a></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://michaeldoyle.eu/blog/server-side-scripting/php/php-how-to-debug-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Select Menu with Current Month Selected</title>
		<link>http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected</link>
		<comments>http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected#comments</comments>
		<pubDate>Mon, 21 Sep 2009 15:04:35 +0000</pubDate>
		<dc:creator>Michael Doyle</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server-side scripting]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[month]]></category>

		<guid isPermaLink="false">http://michaeldoyle.eu/blog/?p=362</guid>
		<description><![CDATA[Here's a PHP class that displays the current month in a select menu list of months:
&#60;?php
$curr_month = date&#40;&#34;m&#34;&#41;;
$month = array &#40;1=&#62;&#34;January&#34;, &#34;February&#34;, &#34;March&#34;, &#34;April&#34;, &#34;May&#34;, &#34;June&#34;, &#34;July&#34;, &#34;August&#34;, &#34;September&#34;, &#34;October&#34;, &#34;November&#34;, &#34;December&#34;&#41;;
$select = &#34;
&#60;select name=\&#34;month\&#34;&#62;\n&#34;;
foreach &#40;$month as $key =&#62; $val&#41; &#123;
    $select .= &#34;\t&#60;option val=\&#34;&#34;.$key.&#34;\&#34;&#34;;
    if &#40;$key == $curr_month&#41; [...]


Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-paginaton' rel='bookmark' title='Permanent Link: PHP &#8211; Paginaton'>PHP &#8211; Paginaton</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here's a PHP class that displays the current month in a select menu list of months:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff;">$curr_month</span> = <a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;m&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$month</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>=&gt;<span style="color: #ff0000;">&quot;January&quot;</span>, <span style="color: #ff0000;">&quot;February&quot;</span>, <span style="color: #ff0000;">&quot;March&quot;</span>, <span style="color: #ff0000;">&quot;April&quot;</span>, <span style="color: #ff0000;">&quot;May&quot;</span>, <span style="color: #ff0000;">&quot;June&quot;</span>, <span style="color: #ff0000;">&quot;July&quot;</span>, <span style="color: #ff0000;">&quot;August&quot;</span>, <span style="color: #ff0000;">&quot;September&quot;</span>, <span style="color: #ff0000;">&quot;October&quot;</span>, <span style="color: #ff0000;">&quot;November&quot;</span>, <span style="color: #ff0000;">&quot;December&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$select</span> = <span style="color: #ff0000;">&quot;
&lt;select name=<span style="color: #000099; font-weight: bold;">\&quot;</span>month<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$month</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$key</span> =&gt; <span style="color: #0000ff;">$val</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$select</span> .= <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;option val=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>.<span style="color: #0000ff;">$key</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$key</span> == <span style="color: #0000ff;">$curr_month</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$select</span> .= <span style="color: #ff0000;">&quot; selected=<span style="color: #000099; font-weight: bold;">\&quot;</span>selected<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span>.<span style="color: #0000ff;">$val</span>.<span style="color: #ff0000;">&quot;&lt;/option&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$select</span> .= <span style="color: #ff0000;">&quot;&gt;&quot;</span>.<span style="color: #0000ff;">$val</span>.<span style="color: #ff0000;">&quot;&lt;/option&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0000ff;">$select</span> .= <span style="color: #ff0000;">&quot;&lt;/select&gt;
&nbsp;
&quot;</span>;
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$select</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
<p>I found this script on: <a href="http://www.finalwebsites.com/forums/topic/select-menu-with-current-month" target="_blank">http://www.finalwebsites.com/forums/topic/select-menu-with-current-month</a></p>


<p>Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-paginaton' rel='bookmark' title='Permanent Link: PHP &#8211; Paginaton'>PHP &#8211; Paginaton</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Validating an Email Addresss</title>
		<link>http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss</link>
		<comments>http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss#comments</comments>
		<pubDate>Tue, 15 Sep 2009 12:16:32 +0000</pubDate>
		<dc:creator>Michael Doyle</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server-side scripting]]></category>
		<category><![CDATA[email validation]]></category>
		<category><![CDATA[validate]]></category>

		<guid isPermaLink="false">http://michaeldoyle.eu/blog/?p=353</guid>
		<description><![CDATA[Countless scripts have been written for validating email addresses in PHP, I've used a few and most seem to work fine. i came across this article (http://www.linuxjournal.com/article/9585) which discusses IETF's documents concerning email address standards. Valid email address are not just in the form of someone@domain.com. Backslashes, more than one "@" symbol are valid in [...]


Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-paginaton' rel='bookmark' title='Permanent Link: PHP &#8211; Paginaton'>PHP &#8211; Paginaton</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected' rel='bookmark' title='Permanent Link: PHP &#8211; Select Menu with Current Month Selected'>PHP &#8211; Select Menu with Current Month Selected</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Countless scripts have been written for validating email addresses in PHP, I've used a few and most seem to work fine. i came across this article (<a href="http://www.linuxjournal.com/article/9585" target="_blank">http://www.linuxjournal.com/article/9585</a>) which discusses IETF's documents concerning email address standards. Valid email address are not just in the form of <em>someone@domain.com</em>. Backslashes, more than one "@" symbol are valid in email addresses as well as other symbols (I didn't look into it much!). There is a lengthy script for validating email addresses included in the article.</p>
<p>However, I couldn't get it to work, maybe I'm just too impatient. There is a good script included in the article which doesn't account for backslashes and the @ symbol. This works quite well for me. (I know, it's bad practice!). I've copied the code and indented it for readability below (and changed the function name, I've tested it out on a live site).</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">function</span> checkEmail<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$email</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//First, we check that there's one @ symbol,</span>
		<span style="color: #808080; font-style: italic;">//and that the lengths are right.</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/ereg"><span style="color: #000066;">ereg</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;^[^@]{1,64}@[^@]{1,255}$&quot;</span>, <span style="color: #0000ff;">$email</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">//Email invalid because wrong number of characters</span>
				<span style="color: #808080; font-style: italic;">//in one section or wrong number of @ symbols.</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">//Split it into sections to make life easier</span>
		<span style="color: #0000ff;">$email_array</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;@&quot;</span>, <span style="color: #0000ff;">$email</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0000ff;">$local_array</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span>, <span style="color: #0000ff;">$email_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span> &lt; <a href="http://www.php.net/sizeof"><span style="color: #000066;">sizeof</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$local_array</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/ereg"><span style="color: #000066;">ereg</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;^(([A-Za-z0-9!#$%&amp;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&amp;↪'*+/=?^_`{|}~<span style="color: #000099; font-weight: bold;">\.</span>-]{0,63})|(<span style="color: #000099; font-weight: bold;">\&quot;</span>[^(<span style="color: #000099; font-weight: bold;">\\</span>|<span style="color: #000099; font-weight: bold;">\&quot;</span>)]{0,62}<span style="color: #000099; font-weight: bold;">\&quot;</span>))$&quot;</span>,<span style="color: #0000ff;">$local_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
					<span style="color: #66cc66;">&#123;</span>
						<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
					<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">//Check if domain is IP. If not,</span>
			<span style="color: #808080; font-style: italic;">//it should be valid domain name</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/ereg"><span style="color: #000066;">ereg</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;^<span style="color: #000099; font-weight: bold;">\[</span>?[0-9<span style="color: #000099; font-weight: bold;">\.</span>]+<span style="color: #000099; font-weight: bold;">\]</span>?$&quot;</span>, <span style="color: #0000ff;">$email_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					<span style="color: #0000ff;">$domain_array</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span>, <span style="color: #0000ff;">$email_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/sizeof"><span style="color: #000066;">sizeof</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$domain_array</span><span style="color: #66cc66;">&#41;</span> &lt; <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>
						<span style="color: #66cc66;">&#123;</span>
							<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Not enough parts to domain</span>
						<span style="color: #66cc66;">&#125;</span>
					<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span> &lt; <a href="http://www.php.net/sizeof"><span style="color: #000066;">sizeof</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$domain_array</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span>
						<span style="color: #66cc66;">&#123;</span>
							<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/ereg"><span style="color: #000066;">ereg</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|↪([A-Za-z0-9]+))$&quot;</span>,<span style="color: #0000ff;">$domain_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
								<span style="color: #66cc66;">&#123;</span>
									<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
								<span style="color: #66cc66;">&#125;</span>
						<span style="color: #66cc66;">&#125;</span>
				<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>If you find this script isn't conforming to correct standards, there's a more complex and updated one at google code:</p>
<p><a href="http://code.google.com/p/php-email-address-validation/" target="_blank">http://code.google.com/p/php-email-address-validation/</a></p>


<p>Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-paginaton' rel='bookmark' title='Permanent Link: PHP &#8211; Paginaton'>PHP &#8211; Paginaton</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected' rel='bookmark' title='Permanent Link: PHP &#8211; Select Menu with Current Month Selected'>PHP &#8211; Select Menu with Current Month Selected</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Retrieve and display your recently listened to tracks from last.fm</title>
		<link>http://michaeldoyle.eu/blog/web/php-retrieve-your-recently-listened-to-tracks-from-last-fm</link>
		<comments>http://michaeldoyle.eu/blog/web/php-retrieve-your-recently-listened-to-tracks-from-last-fm#comments</comments>
		<pubDate>Thu, 03 Sep 2009 21:02:03 +0000</pubDate>
		<dc:creator>Michael Doyle</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://michaeldoyle.eu/blog/?p=335</guid>
		<description><![CDATA[I've been playing around with retrieving my recently listened to tracks from last.fm so that I can use it on my portfolio. Last.fm provides an XML file of recently listened to tracks, so I wrote a php function to retrieve them. Below is the script, it's just basic HTML at the moment so that it [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>I've been playing around with retrieving my recently listened to tracks from <a href="http://www.last.fm" target="_blank">last.fm</a> so that I can use it on my portfolio. Last.fm provides an XML file of recently listened to tracks, so I wrote a php function to retrieve them. Below is the script, it's just basic HTML at the moment so that it can be properly stylised. I've commented all the code so you can see how it works.</p>
<pre class="php"><span style="color: #808080; font-style: italic;">//enter your last.fm username</span>
<span style="color: #0000ff;">$username</span> = <span style="color: #ff0000;">'spahndirge'</span>;
<span style="color: #808080; font-style: italic;">//in seconds, how long to wait until your recently listened tracks are checked for new entries</span>
<span style="color: #0000ff;">$time</span> = <span style="color: #cc66cc;">300</span>;
<span style="color: #808080; font-style: italic;">//this is the URL of the last.fm xml file of your profile</span>
<span style="color: #0000ff;">$lastfmFile</span> = <span style="color: #ff0000;">&quot;http://ws.audioscrobbler.com/1.0/user/$username/recenttracks.xml&quot;</span>;
<span style="color: #808080; font-style: italic;">//the number of tracks you want to display, this can't be above 9</span>
<span style="color: #0000ff;">$numOfTracks</span> = <span style="color: #cc66cc;">5</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getTracks<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$username</span>, <span style="color: #0000ff;">$time</span>, <span style="color: #0000ff;">$lastfmFile</span>, <span style="color: #0000ff;">$numOfTracks</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #808080; font-style: italic;">//this will be the local xml file written to your server</span>
<span style="color: #0000ff;">$myLocalFile</span> = <span style="color: #0000ff;">$username</span>.<span style="color: #ff0000;">'.xml'</span>;
<span style="color: #808080; font-style: italic;">//if the local xml file doesn't exist or if local xml file is older than the time set</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color: #000066;">file_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$myLocalFile</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> || <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/time"><span style="color: #000066;">time</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-<a href="http://www.php.net/filemtime"><span style="color: #000066;">filemtime</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$myLocalFile</span><span style="color: #66cc66;">&#41;</span>&gt;<span style="color: #0000ff;">$time</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//get the last.fm xml file and place it into the contents variable as a string</span>
	<span style="color: #0000ff;">$contents</span> = @<a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lastfmFile</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//open the local file or create it if it doesn't exist</span>
	<span style="color: #0000ff;">$temp</span> = <a href="http://www.php.net/fopen"><span style="color: #000066;">fopen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$myLocalFile</span>, <span style="color: #ff0000;">&quot;w&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//write the contents of the lastfmFile to the local file</span>
	<a href="http://www.php.net/fwrite"><span style="color: #000066;">fwrite</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$temp</span>, <span style="color: #0000ff;">$contents</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//close the file</span>
	<a href="http://www.php.net/fclose"><span style="color: #000066;">fclose</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$temp</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">//grab the local xml file and place it into the xml variable</span>
<span style="color: #0000ff;">$xml</span> = @simplexml_load_file<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$myLocalFile</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//create an unordered list of the track name and artist from the local XML file</span>
<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;
&lt;ul&gt;&quot;</span>;
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$t</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$t</span> &lt;= <span style="color: #0000ff;">$numOfTracks</span>; <span style="color: #0000ff;">$t</span>++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>
&lt;li&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>.<span style="color: #0000ff;">$xml</span>-&gt;<span style="color: #006600;">track</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$t</span><span style="color: #66cc66;">&#93;</span>-&gt;<span style="color: #006600;">url</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> target=<span style="color: #000099; font-weight: bold;">\&quot;</span>_blank<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span>.<span style="color: #0000ff;">$xml</span>-&gt;<span style="color: #006600;">track</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$t</span><span style="color: #66cc66;">&#93;</span>-&gt;<span style="color: #006600;">name</span>.<span style="color: #ff0000;">&quot; - &quot;</span>.<span style="color: #0000ff;">$xml</span>-&gt;<span style="color: #006600;">track</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$t</span><span style="color: #66cc66;">&#93;</span>-&gt;<span style="color: #006600;">artist</span>.<span style="color: #ff0000;">&quot;&lt;/a&gt;&lt;/li&gt;
&nbsp;
&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&lt;/ul&gt;
&nbsp;
&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
getTracks<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$username</span>, <span style="color: #0000ff;">$time</span>, <span style="color: #0000ff;">$lastfmFile</span>, <span style="color: #0000ff;">$numOfTracks</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>It isn't the most efficient code, but it works!</p>
<p>I set the time to 300 seconds (5 minutes), it's around the average time it takes to listen to a song. This is to reduce server load and loading times; there's no point in checking for a new song every minute or two.</p>
<p>If you have any improvements on the script, let me know.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://michaeldoyle.eu/blog/web/php-retrieve-your-recently-listened-to-tracks-from-last-fm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Regular Expressions</title>
		<link>http://michaeldoyle.eu/blog/server-side-scripting/php/php-regular-expressions</link>
		<comments>http://michaeldoyle.eu/blog/server-side-scripting/php/php-regular-expressions#comments</comments>
		<pubDate>Wed, 29 Jul 2009 11:47:12 +0000</pubDate>
		<dc:creator>Michael Doyle</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://michaeldoyle.eu/blog/?p=220</guid>
		<description><![CDATA[Catswhocode have a very good summarey of Regular expressions:
http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers


Related posts:PHP &#8211; Validating an Email Addresss



Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.catswhocode.com/blog/" target="_blank">Catswhocode</a> have a very good summarey of Regular expressions:</p>
<p><a href="http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers" target="_blank">http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers</a></p>


<p>Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michaeldoyle.eu/blog/server-side-scripting/php/php-regular-expressions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Paginaton</title>
		<link>http://michaeldoyle.eu/blog/server-side-scripting/php-paginaton</link>
		<comments>http://michaeldoyle.eu/blog/server-side-scripting/php-paginaton#comments</comments>
		<pubDate>Sat, 04 Jul 2009 15:00:46 +0000</pubDate>
		<dc:creator>Michael Doyle</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server-side scripting]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://michaeldoyle.eu/blog/?p=216</guid>
		<description><![CDATA[i found a very good php pagination script that can be easily customised to suit any need. It's located at:
http://phpsense.com/php/php-pagination-script.html


Related posts:PHP &#8211; Validating an Email Addresss
PHP &#8211; Select Menu with Current Month Selected



Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected' rel='bookmark' title='Permanent Link: PHP &#8211; Select Menu with Current Month Selected'>PHP &#8211; Select Menu with Current Month Selected</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>i found a very good php pagination script that can be easily customised to suit any need. It's located at:</p>
<p><a href="http://phpsense.com/php/php-pagination-script.html" target="_blank">http://phpsense.com/php/php-pagination-script.html</a></p>


<p>Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected' rel='bookmark' title='Permanent Link: PHP &#8211; Select Menu with Current Month Selected'>PHP &#8211; Select Menu with Current Month Selected</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michaeldoyle.eu/blog/server-side-scripting/php-paginaton/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Time and Date</title>
		<link>http://michaeldoyle.eu/blog/server-side-scripting/php-time-and-date</link>
		<comments>http://michaeldoyle.eu/blog/server-side-scripting/php-time-and-date#comments</comments>
		<pubDate>Tue, 09 Jun 2009 14:53:34 +0000</pubDate>
		<dc:creator>Michael Doyle</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server-side scripting]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://michaeldoyle.eu/blog/?p=198</guid>
		<description><![CDATA[I always find server time gives me little headache due to abbreviations and time zones. Here's a simple article that shows the simple ways to format the date and time.
http://www.landofcode.com/php/php-date-and-time.php


Related posts:PHP &#8211; Select Menu with Current Month Selected
PHP &#8211; Validating an Email Addresss



Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected' rel='bookmark' title='Permanent Link: PHP &#8211; Select Menu with Current Month Selected'>PHP &#8211; Select Menu with Current Month Selected</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I always find server time gives me little headache due to abbreviations and time zones. Here's a simple article that shows the simple ways to format the date and time.</p>
<p><a href="http://www.landofcode.com/php/php-date-and-time.php" target="_blank">http://www.landofcode.com/php/php-date-and-time.php</a></p>


<p>Related posts:<ol><li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-select-menu-with-current-month-selected' rel='bookmark' title='Permanent Link: PHP &#8211; Select Menu with Current Month Selected'>PHP &#8211; Select Menu with Current Month Selected</a></li>
<li><a href='http://michaeldoyle.eu/blog/server-side-scripting/php-validating-an-email-addresss' rel='bookmark' title='Permanent Link: PHP &#8211; Validating an Email Addresss'>PHP &#8211; Validating an Email Addresss</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://michaeldoyle.eu/blog/server-side-scripting/php-time-and-date/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

