<?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>Kalkran.COM</title>
	<atom:link href="http://kalkran.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kalkran.com</link>
	<description>Design&#38;Coding</description>
	<lastBuildDate>Fri, 26 Feb 2010 15:48:50 +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>Making graphs with PHP</title>
		<link>http://kalkran.com/misc/making-graphs-with-php/</link>
		<comments>http://kalkran.com/misc/making-graphs-with-php/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 15:46:19 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=201</guid>
		<description><![CDATA[Like I promised yesterday, here's the tutorial for creating little fancy graphs.
Actual result:

SOURCE
First things first. Figure out what offsets you will need to display the graph in. Easiest way is to do this by drawing up a little box on a piece of paper or in paint. If you're too lazy for this, there's one [...]]]></description>
			<content:encoded><![CDATA[<p>Like I promised yesterday, here's the tutorial for creating little fancy graphs.</p>
<p>Actual result:<br />
<img src="http://kalkran.com/tezt/tut.php" /><br />
<a href="http://kalkran.com/tezt/tut.phps">SOURCE</a></p>
<p>First things first. Figure out what offsets you will need to display the graph in. Easiest way is to do this by drawing up a little box on a piece of paper or in paint. If you're too lazy for this, there's one after the jump:</p>
<p><span id="more-201"></span></p>
<p><a href="http://kalkran.com/wp-content/uploads/marign.png"><img class="alignnone size-full wp-image-202" title="Margin" src="http://kalkran.com/wp-content/uploads/marign.png" alt="" width="348" height="234" /></a></p>
<p>And you need to know that the X and Y-coordinates you need always start at the <strong>top left</strong>.</p>
<p>Let us jump right into the beginning and create an actual image.</p>
<pre class="php"><span style="color: #0000ff;">$img</span> = imagecreate<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">160</span>,<span style="color: #cc66cc;">110</span><span style="color: #66cc66;">&#41;</span>;
imagecolorallocatealpha<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span>, <span style="color: #cc66cc;">247</span>,<span style="color: #cc66cc;">247</span>,<span style="color: #cc66cc;">247</span>,<span style="color: #cc66cc;">127</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>They speak for theirselves. We're making an image 160 pixels wide by 110 pixels high (110 pixels is easy to make this work with; 5 pixels margin and you have 100 pixels height left. Thats 1 pixel for each percent.). Then we assign the background colour for this image. Namely rgb(247,247,247), but beware because the last argument we passed is the transparency, where 0 means completely opaque and 127 completely see-through.</p>
<p>So now we have a 160x110 pixel transparent image. What I like to do now is add a black line that defines the lower bound, or the line that represents zero in this case. But before we can do this, we need to assign some colours.</p>
<pre class="php"><span style="color: #0000ff;">$black</span> = imagecolorallocate<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$graph</span> = imagecolorallocate<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span>,<span style="color: #cc66cc;">47</span>,<span style="color: #cc66cc;">116</span>,<span style="color: #cc66cc;">168</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$shadow</span> = imagecolorallocate<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span>,<span style="color: #cc66cc;">195</span>,<span style="color: #cc66cc;">195</span>,<span style="color: #cc66cc;">195</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Now it's time to draw the actual line, for this we use the function imageline(handle, Xstart, Ystart, Xend, Yend, colour). The X is the offset to the right. Since it's a horizontal line we'll draw the line from 5 - 155 and leave a 5 px border. The height at which we need to draw is 110 - margin, so 105 pixels deep.</p>
<pre class="php">imageline<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">105</span>, <span style="color: #cc66cc;">155</span>, <span style="color: #cc66cc;">105</span>, <span style="color: #0000ff;">$black</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>We now have the base line, and we know how much higher it can go (100 px). But since the coordinates start at the top left instead of bottom left like in a graph, we will need the complement of the height. So for example:</p>
<pre class="php"><span style="color: #0000ff;">$y</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">105</span> - <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Let's assume you have all values in an array. We'll read them in to our own array with X and Y coordinates so we can use it with imagefilledpolygon(). Thing is, if we want a filled graph (we do), we'll also need to specify the baseline so it knows from where to fill. And instead of starting on top of the base, we'll start 1 px higher.</p>
<pre class="php"><span style="color: #0000ff;">$points</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;">5</span>, <span style="color: #cc66cc;">104</span>,
	<span style="color: #cc66cc;">155</span>, <span style="color: #cc66cc;">104</span>,
<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$pos</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$key</span> =&gt; <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$points</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pos</span>+= <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$points</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #cc66cc;">104</span>-<span style="color: #0000ff;">$value</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>I'll assume you have an array with size 30 so we can draw a point every 5px.  If you don't, put this before the points key to fill in some random numbers.</p>
<pre class="php"><span style="color: #0000ff;">$array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</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;= <span style="color: #cc66cc;">30</span>; <span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span>
	<span style="color: #0000ff;">$array</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <a href="http://www.php.net/rand"><span style="color: #000066;">rand</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">70</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>And don't forget to show it with imagefilledpolygon(handle, pointArray, pointCount, colour):</p>
<pre class="php">imagefilledpolygon<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span>, <span style="color: #0000ff;">$points</span>, <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$points</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #cc66cc;">2</span>, <span style="color: #0000ff;">$graph</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Now we'll have created this:</p>
<p><img src="http://kalkran.com/wp-content/uploads/tut.png" alt="" title="tut" width="160" height="110" class="alignnone size-full wp-image-209" /></p>
<p>Bit bleak isn't it?<br />
I'm no graphical designer by far, but I do like the looks of adding a little shadow behind the actual graph.<br />
Try inserting this part before the foreach() loop:</p>
<pre class="php"><span style="color: #0000ff;">$highlight</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;">3</span>, <span style="color: #cc66cc;">104</span>, <span style="color: #cc66cc;">153</span>, <span style="color: #cc66cc;">104</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>And editing the loop that it says this instead:</p>
<pre class="php"><span style="color: #0000ff;">$pos</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$key</span> =&gt; <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$highlight</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pos</span> + <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Two pixels to the left</span>
	<span style="color: #0000ff;">$highlight</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #cc66cc;">104</span> - <span style="color: #0000ff;">$value</span> + <span style="color: #cc66cc;">3</span>;  <span style="color: #808080; font-style: italic;">// And three pixels up</span>
	<span style="color: #0000ff;">$points</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pos</span>+= <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$points</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #cc66cc;">104</span>-<span style="color: #0000ff;">$value</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>And don't forget to show this polygon BEFORE you output the actual graph.</p>
<pre class="php">imagefilledpolygon<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span>, <span style="color: #0000ff;">$highlight</span>, <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$highlight</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #cc66cc;">2</span>, <span style="color: #0000ff;">$shadow</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>And last, but definitely not least, output the graph:</p>
<pre class="php"><a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Content-Type: image/png'</span><span style="color: #66cc66;">&#41;</span>;
imagepng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$img</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Result:<br />
<img src="http://kalkran.com/wp-content/uploads/tut1.png" alt="" title="tut" width="160" height="110" class="alignnone size-full wp-image-210" /></p>
<p>Ta da!</p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=201&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/making-graphs-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NAS Usage</title>
		<link>http://kalkran.com/personal-blog/nas-usage/</link>
		<comments>http://kalkran.com/personal-blog/nas-usage/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:30:10 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[Personal Blog]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=196</guid>
		<description><![CDATA[As I've said in my previous posts, I'm now hosting the website on my NAS downstairs.
It comes with a lot of options, but I'd still like a few more options to have more control over what it does, without having to log into the SSH every time. That's why I'm working on an admin panel [...]]]></description>
			<content:encoded><![CDATA[<p>As I've said in my previous posts, I'm now hosting the website on my NAS downstairs.</p>
<p>It comes with a lot of options, but I'd still like a few more options to have more control over what it does, without having to log into the SSH every time. That's why I'm working on an admin panel for some administration options. Of which the first function is the CPU / Memory monitor I've made.. I've included them on the right, because I wanted to try and make a Wordpress widget as well.</p>
<p>I've still got a slight problem, though, I'd also like a network monitor. I've tried iptables, but it's not easy to get it to work and I'm not going to recompile my NAS kernel and void my warranty. Any other suggestions are very welcome!</p>
<p>Tutorial on those graphs coming up.</p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=196&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/personal-blog/nas-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LF Job</title>
		<link>http://kalkran.com/misc/lf-job/</link>
		<comments>http://kalkran.com/misc/lf-job/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 14:35:34 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=194</guid>
		<description><![CDATA[After giving up on my second attempted college study, due to a lack of interest and challenge, I am now desperately looking for a job.
The study in question was of a Math Teacher, what was I thinking? Ever since the first day, no challenge whatsoever. I'm not a genius, but this was highschool all over [...]]]></description>
			<content:encoded><![CDATA[<p>After giving up on my second attempted college study, due to a lack of interest and challenge, I am now desperately looking for a job.</p>
<p>The study in question was of a Math Teacher, what was I thinking? Ever since the first day, no challenge whatsoever. I'm not a genius, but this was highschool all over again. I managed to pass the first math test without ever going to college. And then the other things I had to learn about.. Who cares what stages teenagers go through to reach adulthood? Although we did have some laughs about babies, when they have no sense of 'object permanence', so when you take something away from them, they think it's actually gone for good. Or when you put two rows of five pieces of candy in front of a seven or eight year old and he'll pick the row of candies which takes up the most space, because he thinks there are more..</p>
<p>Anyway, my qualifications aren't very impressive, I have to admit. I should be able to find a job nonetheless you'd say. A young guy, who is a fast learner and manages to go from having no work experience to running a shop in approx. six months. If I see all them people doing nothing and being able to afford a house, why can't I be like that? :( I'm lazy, yes. Sue me.</p>
<p>I've really been applying everywhere I can, from receptionist or police officer to a temporary job as a web developer. But hardly anyone even replies to say they've received my application.</p>
<p>Wish me luck.</p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=194&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/lf-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Host</title>
		<link>http://kalkran.com/misc/new-host/</link>
		<comments>http://kalkran.com/misc/new-host/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 15:54:45 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=190</guid>
		<description><![CDATA[Right,
Instead of having this website hosted at a company, I'm now hosting it from the electricity cupboard thing :).
The hosting computer is running some kind of Linux called BusyBox. It's processor is of some brand nobody has ever heard about but it's running great.
Inside are 2x 1 TB Western Digital Green harddisks, of which one [...]]]></description>
			<content:encoded><![CDATA[<p>Right,</p>
<p>Instead of having this website hosted at a company, I'm now hosting it from the electricity cupboard thing :).</p>
<p>The hosting computer is running some kind of Linux called BusyBox. It's processor is of some brand nobody has ever heard about but it's running great.</p>
<p>Inside are 2x 1 TB Western Digital Green harddisks, of which one is currently in hibernation mode all the time, because I'm still trying to fill up the first disk with movies and games.</p>
<p>It's a Synology 210j, which I can really recommend to anyone who wants to have their own <acronym title="Network Administration Storage">NAS</acronym>. It's a download center, a PHP/MySQL server and it's hosting my movies and music through DLNA so my father can watch it downstairs on his television. Other features these NAS'es have are third party packages, so you can install pretty much anything you want on them. For example, I've installed a package called SABNZBD which serves as a download center for downloading from newsgroups and will also unpack and repair the archives, unlike the built-in download center.</p>
<p>Unfortunately, due to my internet - which likes to die about 4-5+ times per day - the site will have some more downtime, although, it can't be much worse than the previous host. Back when I still used WeBBuddy site monitoring, I got mail from them every day saying they couldn't connect to my website. Usually during off-hours, but still...</p>
<p>Of course, site performance will suffer a little, but it shouldnt be too bad. Only moments when the site should be loading slow is when it's unpacking / repairing archives or between 0.00 and 9.00 CET in the morning when I set it to download at full speed (30 Mbit internet and getting about 26 Mbit download speeds during the night).</p>
<p>Kalkran out,</p>
<p>PS Yes, I'll try update some more. Even if it's just about the games I play or made something new in php :).</p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=190&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/new-host/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wolfram Alpha</title>
		<link>http://kalkran.com/featured/wolfram-alpha/</link>
		<comments>http://kalkran.com/featured/wolfram-alpha/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 12:56:28 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://kalkran.com/misc/wolfram-alpha/</guid>
		<description><![CDATA[After doing some school work, I was browsing through a dutch website about math (www.wiskundemeisjes.nl), and in one of the comments linked a site called Wolfram&#124;Alpha... This is the best search engine EVER.
Or, not so much a search engine.. It's a knowledge engine. It can solve almost all your math problems, you can ask it [...]]]></description>
			<content:encoded><![CDATA[<p>After doing some school work, I was browsing through a dutch website about math (www.wiskundemeisjes.nl), and in one of the comments linked a site called Wolfram|Alpha... This is the best search engine EVER.<br />
Or, not so much a search engine.. It's a knowledge engine. It can solve almost all your math problems, you can ask it how many days seconds years have passed since your birthday.. Who was born on that day... Or check how much 5 mol of silver nitrate is!<br />
Just check it out:</p>
<p><a title="Wolfram|Alpha" href="http://www.wolframalpha.com">www.wolframalpha.com</a></p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=188&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/featured/wolfram-alpha/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Left 4 Dead</title>
		<link>http://kalkran.com/games/left-4-dead/</link>
		<comments>http://kalkran.com/games/left-4-dead/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 20:35:42 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[Video Games]]></category>

		<guid isPermaLink="false">http://kalkran.com/?p=185</guid>
		<description><![CDATA[
Great game, this is..
]]></description>
			<content:encoded><![CDATA[<p><object width="480" height="295" data="http://www.youtube.com/v/mNhaFCQIRWE&amp;hl=nl&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/mNhaFCQIRWE&amp;hl=nl&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>
<p>Great game, this is..</p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=185&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/games/left-4-dead/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What would you do?</title>
		<link>http://kalkran.com/misc/what-would-you-do/</link>
		<comments>http://kalkran.com/misc/what-would-you-do/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 22:06:53 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://kalkran.com/misc/what-would-you-do/</guid>
		<description><![CDATA[Here's just quick post in between.
I've been thinking about this a lot for the last couple of days/weeks. What would I do if suddenly everyone disappeared, I mean everyone. Would you shoot yourself? Would you rob the stores? Would you try to fly an airplane and head to warmer climates? Would you do the same [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_180" class="wp-caption alignright" style="width: 136px"><img class="size-medium wp-image-180" title="bank-vault-door" src="http://kalkran.com/wp-content/uploads/bank-vault-door-300x224.jpg" alt="Would you try break open the local bank vault?" width="126" height="94" /><p class="wp-caption-text">Would you try and break open the local bank vault?</p></div>
<p>Here's just quick post in between.</p>
<p>I've been thinking about this a lot for the last couple of days/weeks. What would I do if suddenly everyone disappeared, I mean <strong>everyone</strong>. Would you shoot yourself? Would you rob the stores? Would you try to fly an airplane and head to warmer climates? Would you do the same thing, but by car?</p>
<p>What I would probably do, is take my parents car, and drive as far south as I can get, then refuel for free (nobody there to stop you from stealing petrol) and just keep on driving until I got somewhere warm. Then I would probably just chill out there for a while. But wouldn't this get boring (read: lonely)?</p>
<p>So, what would you do?</p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=178&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/misc/what-would-you-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IRC Bot (part 2)</title>
		<link>http://kalkran.com/tutorials/irc-bot-part-2/</link>
		<comments>http://kalkran.com/tutorials/irc-bot-part-2/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 22:43:30 +0000</pubDate>
		<dc:creator>Kalkran</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.kalkran.com/?p=30</guid>
		<description><![CDATA[Part 1
This lesson's goals

Set up a MySQL database
Check every message for incoming commands
Update commands dynamically

Yes, that's quite a challenge. Unlike the previous tutorial, I'd call this an average tutorial. Not too hard, but not truly easy either. Full tutorial after the jump.
Good, so you decided to follow up from the previous tutorial and make it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://kalkran.com/tutorials/irc-bot-part-1/">Part 1</a></p>
<h3>This lesson's goals</h3>
<ul>
<li>Set up a MySQL database</li>
<li>Check every message for incoming commands</li>
<li>Update commands dynamically</li>
</ul>
<p>Yes, that's quite a challenge. Unlike the previous tutorial, I'd call this an average tutorial. Not too hard, but not truly easy either. Full tutorial after the jump.</p>
<p>Good, so you decided to follow up from the previous tutorial and make it do what you want? The bot will be controlled through the IRC window itself by sending it different queries.</p>
<p>Let's start by laying out a work plan, things we want it to do:</p>
<ul>
<li>Add your own functions (!hai =&gt; Say something back; !slap =&gt; Slap someone, etc)</li>
<li>Track user stats (Words per line, #of lines, #of words, avg. #of characters per word, etc.)</li>
</ul>
<p>That's what we'll be covering this tutorial. We'll keep the functions and user data stored in a MySQL database.<br />
<span id="more-30"></span></p>
<h3>Set up the MySQL tables</h3>
<p>First we need to think of what we want to store exactly.</p>
<p>For the functions we'd like a function name, and what it should do. That's easy, two colums. 'func' and 'eval', func stores the name and eval the actions it should perform.</p>
<p>Easy! Just run the following set of queries on the database of your choice:<br />
Create a database:</p>
<pre class="mysql"><span style="color: #993333; font-weight: bold;">CREATE DATABASE</span> `bot`;</pre>
<p>Create a table in the database:</p>
<pre class="mysql"><span style="color: #993333; font-weight: bold;">CREATE TABLE</span> `funcs` <span style="color: #66cc66;">&#40;</span>
&nbsp;
`func` <span style="color: #aa9933; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">255</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
&nbsp;
`eval` <span style="color: #aa9933; font-weight: bold;">TEXT</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
&nbsp;
<span style="color: #66cc66;">&#41;</span> ENGINE = MYISAM ;</pre>
<p>Now. A table for the users stats. We want to store the amount of lines, words, characters and of course their username.</p>
<pre class="mysql"><span style="color: #993333; font-weight: bold;">CREATE TABLE</span> `users` <span style="color: #66cc66;">&#40;</span>
&nbsp;
`username` <span style="color: #aa9933; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">255</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
&nbsp;
`chars` <span style="color: #aa9933; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">16</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
&nbsp;
`<span style="color: #993333; font-weight: bold;">LINES</span>` <span style="color: #aa9933; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">16</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
&nbsp;
`words` <span style="color: #aa9933; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">16</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
&nbsp;
<span style="color: #66cc66;">&#41;</span> ENGINE = MYISAM ;</pre>
<p>Okay, so that's the database set up. Now go to the beginning of your bot file. Right after the set_time_limit(0); you want to add your connection details:</p>
<pre class="php"><span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'host'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'username'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'password'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'database'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Connect to mysql database</span>
&nbsp;
<a href="http://www.php.net/mysql_connect"><span style="color: #000066;">mysql_connect</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'host'</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'username'</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'password'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #000066;">mysql_error</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<a href="http://www.php.net/mysql_select_db"><span style="color: #000066;">mysql_select_db</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$mysql</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'database'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #000066;">mysql_error</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Okay, awesome. We have a database connection now. Now we just need to initialize the bot functions. You might want to make a separate function for that called getFunctions();</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">function</span> getFunctions <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$result</span> = <a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SELECT * FROM `funcs`&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Select all functions from the database</span>
	<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$temp</span> = <a href="http://www.php.net/mysql_fetch_array"><span style="color: #000066;">mysql_fetch_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #0000ff;">$functions</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$temp</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'func'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$temp</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'eval'</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #808080; font-style: italic;">// This function is mandatory, it reads all the functions in again, allowing you to add functions while the bot is running:</span>
	<span style="color: #0000ff;">$functions</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'rehash'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">'$funcs = getFunctions();sendMsg(<span style="color: #000099; font-weight: bold;">\'</span>Functions reloaded. Loaded <span style="color: #000099; font-weight: bold;">\'</span>.count($functions).<span style="color: #000099; font-weight: bold;">\'</span> functions.<span style="color: #000099; font-weight: bold;">\'</span>, $to);'</span>;
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$functions</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Every time you call this function it will return an array with all the functions inside! Then, whenever a user says something that begins with an exclamation mark, check for known commands. But before this'll work, we need to get some information from the strings we receive, which go something like: PRIVMSG #channel Name: Message. I've made a few functions you can copy:</p>
<pre class="php">    <span style="color: #000000; font-weight: bold;">function</span> getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Get the actual message</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;PRIVMSG&quot;</span>, <span style="color: #0000ff;">$in</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> <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span>, <a href="http://www.php.net/strpos"><span style="color: #000066;">strpos</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span>, <span style="color: #ff0000;">&quot;:&quot;</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</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: #000000; font-weight: bold;">function</span> getTo<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Get who the message is directed to (channel or privately?)</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;PRIVMSG&quot;</span>, <span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0000ff;">$t</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;">$in</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0000ff;">$user</span> = <a href="http://www.php.net/trim"><span style="color: #000066;">trim</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$t</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</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/ereg"><span style="color: #000066;">ereg</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;#&quot;</span>, <span style="color: #0000ff;">$user</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$user</span> = getWho<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$user</span>;
        <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</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: #000000; font-weight: bold;">function</span> getWho<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Get who sent the message</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;PRIVMSG&quot;</span>, <span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0000ff;">$t</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;">$in</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0000ff;">$user</span> = <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$t</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$user</span>;
        <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</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: #000000; font-weight: bold;">function</span> sendMsg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$msg</span>, <span style="color: #0000ff;">$to</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <a href="http://www.php.net/fputs"><span style="color: #000066;">fputs</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span>, <span style="color: #ff0000;">'PRIVMSG '</span> . <span style="color: #0000ff;">$to</span> . <span style="color: #ff0000;">' :'</span> . <span style="color: #0000ff;">$msg</span>  . <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #66cc66;">&#125;</span></pre>
<p>Just add this near the top of your file. Then add the following in "The Loop":</p>
<pre class="php"><span style="color: #808080; font-style: italic;">// While the handle still exists and not at the end of file yet :)</span>
<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span> || !<a href="http://www.php.net/feof"><span style="color: #000066;">feof</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$in</span> = <a href="http://www.php.net/fread"><span style="color: #000066;">fread</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span>, <span style="color: #cc66cc;">512</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Read until we have 512 bytes at a time. Save the results in $in.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/eregi"><span style="color: #000066;">eregi</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;PING&quot;</span>, <span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span> &amp;amp;&amp;amp; !<a href="http://www.php.net/eregi"><span style="color: #000066;">eregi</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;PRIVMSG&quot;</span>, <span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		@<a href="http://www.php.net/fputs"><span style="color: #000066;">fputs</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span>, <span style="color: #ff0000;">&quot;PONG &quot;</span> . <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span>, <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Start adding here</span>
	<span style="color: #0000ff;">$msg</span> = getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$to</span> = getTo<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$from</span> = getWho<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$in</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Stop here ;)</span>
<span style="color: #808080; font-style: italic;">// End of loop</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>So now we have three variables we can use within the loop. This is very useful for sending messages back (Who are we sending it to?). Now we need to initialize the functions, it's no good checking for commands if we can't read the actual functions. Add this before the loop:</p>
<pre class="php">	<span style="color: #0000ff;">$funcs</span> = getFunctions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Store the functions in $funcs</span></pre>
<p>Now we need to start checking incoming messages for commands to be executed. So add this within the loop, right before the loop ends</p>
<pre class="php"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$message</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">'!'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// The message starts with an exclamation mark, see if we have a corresponding function:</span>
	<span style="color: #0000ff;">$x</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$msg</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// we don't want to check the rest of the message yet.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$funcs</span><span style="color: #66cc66;">&#91;</span><a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</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: #808080; font-style: italic;">// if we have a function that matches the first 'word' in the sentence apart from the exclamation mark:</span>
		<a href="http://www.php.net/eval"><span style="color: #000066;">eval</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$funcs</span><span style="color: #66cc66;">&#91;</span><a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Eval() it.</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>That's pretty much it. Next lesson will cover tracking user statistics.</p>
<img src="http://kalkran.com/?ak_action=api_record_view&id=30&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kalkran.com/tutorials/irc-bot-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
