<?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>MattyBatty &#187; Tutorials</title>
	<atom:link href="http://www.mattybatty.co.uk/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattybatty.co.uk</link>
	<description>Home of all things tech!</description>
	<lastBuildDate>Wed, 17 Mar 2010 17:39:53 +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; Fun with Functions</title>
		<link>http://www.mattybatty.co.uk/2009/08/07/php-fun-with-functions/</link>
		<comments>http://www.mattybatty.co.uk/2009/08/07/php-fun-with-functions/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 15:00:04 +0000</pubDate>
		<dc:creator>MattyBatty</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.mattybatty.co.uk/?p=460</guid>
		<description><![CDATA[Hopefully you are pretty secure with the basics of PHP by now. If not, you should read part 1 and part 2 of this series. This part is about functions. What are they; how do you use them; and how can you utilise your own functions? Functions can be a great tool to speed up [...]<p><a href="http://www.mattybatty.co.uk/2009/08/07/php-fun-with-functions/">PHP &#8211; Fun with Functions</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Hopefully you are pretty secure with the basics of PHP by now. If not, you should read <a title="Part 1 - PHP - The Basics" href="http://www.mattybatty.co.uk/2009/07/24/php-the-basics/" target="_self">part 1</a> and <a title="Part 2 - PHP - Your Next Steps" href="http://www.mattybatty.co.uk/2009/07/31/php-your-next-steps/" target="_self">part 2</a> of this series. This part is about functions. What are they; how do you use them; and how can you utilise your own functions? Functions can be a great tool to speed up your coding and to make applications run much more smoothly, so let&#8217;s go!</p>
<h3>What are functions?</h3>
<p>Functions are blocks of code that can be called upon at any point in the script to perform a particular task or &#8216;function&#8217;. There are more than 750 functions built into a normal install of PHP, but you can define your own too, making them very versatile and easy.<span id="more-460"></span></p>
<h3>How do I use functions?</h3>
<p>You use functions by calling them from within your code, this can be done anywhere in the script, and for built-in functions, it does not require any extra code or a file to be included.</p>
<p>One useful function which is built in is strlen, this returns the length of the string which you input, for example:</p>
<pre>&lt;?php
$length = strlen("MattyBatty"); //This sets the value of $length to the strlen of 'MattyBatty'
echo $length; //This would echo '10'
?&gt;</pre>
<p>The &#8220;MattyBatty&#8221; part is what we call an <strong>argument</strong>, this is a variable which is passed to a function which allows it to perform a different task or have a different output depending on what is put in.</p>
<h3>The Best Bit</h3>
<p>Probably the best bit about functions is the ability to write your own. This means that instead of writing the same piece of code over and over again to use with different strings, you can write a function and have the string as the argument. A common use for functions is for mathematical calculations. For example, you could create the function add(), or multiply() like this.</p>
<pre>&lt;?php
function multiply($num1, $num2) //Defines the function and the argument names.
   {
   return $num1*$num2; //Multiplies the two numbers and returns the result.
   }
?&gt;</pre>
<p><em>Explained &#8211; </em>First, we define the function using the word &#8216;function&#8217;. This tells PHP we are about to write a function. We then give the function a name, in this case, &#8216;multiply&#8217;. Next, we give the arguments names, separated by commas. This is so when someone calls the function like this:</p>
<pre>&lt;?php
echo multiply(3,4);
?&gt;</pre>
<p>$num1 becomes 3 and $num2 becomes 4. We then enclose the actual &#8216;task&#8217; in curly brackets { }. Inside these we use the word return so that the function returns the answer to the code that called it, ready to be echo&#8217;d or used in a different function.</p>
<p>Of course, functions can be <strong>much</strong> more complex than that. I was just giving you a taster into the world of PHP functions. I hope you have enjoyed my short series of tutorials and I hope you now understand PHP a little better. Thank you for reading my series, and make sure you check out the other two as well. You never know, you might learn something new!</p>
<p><a href="http://www.mattybatty.co.uk/2009/08/07/php-fun-with-functions/">PHP &#8211; Fun with Functions</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattybatty.co.uk/2009/08/07/php-fun-with-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Call of Duty: World at War Tips</title>
		<link>http://www.mattybatty.co.uk/2009/08/04/call-of-duty-world-at-war-tips/</link>
		<comments>http://www.mattybatty.co.uk/2009/08/04/call-of-duty-world-at-war-tips/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 07:00:02 +0000</pubDate>
		<dc:creator>Harry Battison</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[activision]]></category>
		<category><![CDATA[call of duty]]></category>
		<category><![CDATA[COD]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[grenade]]></category>
		<category><![CDATA[gun]]></category>
		<category><![CDATA[infinity ward]]></category>
		<category><![CDATA[nazi]]></category>
		<category><![CDATA[tactics]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[treyarch]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WaW]]></category>
		<category><![CDATA[world at war]]></category>
		<category><![CDATA[zombie]]></category>

		<guid isPermaLink="false">http://www.mattybatty.co.uk/?p=398</guid>
		<description><![CDATA[This is my first ever little bit of teaching to you people out there, so I&#8217;m going to make it kind of simple by just giving you a few tips on a well known game. Call of Duty &#8211; or COD &#8211; has been a huge success since it was first released. They are war [...]<p><a href="http://www.mattybatty.co.uk/2009/08/04/call-of-duty-world-at-war-tips/">Call of Duty: World at War Tips</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This is my first ever little bit of teaching to you people out there, so I&#8217;m going to make it kind of simple by just giving you a few tips on a well known game. Call of Duty &#8211; or COD &#8211; has been a huge success since it was first released. They are war games and the most recent release has been the 5th game called: Call of Duty &#8211; World at War. This game is set in WWII and covers both the battles between the Russians and Germans and the Americans against the Japanese. The game-play covers everything from on-line multilayer mode and co-op campaigns to a gruesome and gruelling fight with Nazi Zombies.</p>
<p>I quite like this game but my friend likes it a whole lot more. He loves the game and plays the many different modes, he is 3rd prestige, level 55. Him and I will be giving you a few tips about gun classes and more. We will also be giving you a short review of the amazing Nazi Zombies and to top it of we will talk about the very recent map pack releases.<span id="more-398"></span></p>
<p>First my friend [iiMaDMiXxSx] is going to tell you about his superb classes. &#8216;There are many great combos you can have, for example a stealthy class for maps like Courtyard, Hanger, and Sub-pens. A good class to have on those courses would be some sort of sub machine gun with camouflage, suppressor, and bomb squad. (the other perk isn&#8217;t that important) On the other hand you could go for a sniper class with juggernaut and betties. (you may need to have a good hand with a pistol for enemies too close.)</p>
<p>There are also many other tactics you can use on practically every course as all of the courses can be all out fights. This usually depends on the type of battle but on just a normal team death match all out courses would be: Dome, Asylum and Corrosion. In my opinion great classes to have on these courses are something like the MP40 or Thompson with dual magazines, stopping power or juggernaut and steady aim.</p>
<p>There are also many types of rifles and they each have their own courses that they are good on. Such as rifles like the SVT, M1A1 Carbine  or Gewher are ideal on big maps such as; Round House, Banzai downfall and finally seelow. STG44 are also pretty good but they are more all-round guns, they are also very good with double tap. Finally my friend&#8217;s favourite map in general is Castle and in my opinion it would have to be Corrosion.</p>
<p>Another thing we would like to give you tips on is the Shi No Numa Nazi Zombies level. To start off with I will tell you 3 of the many  great tactics to use:</p>
<ol>
<li>In round 1 do <span style="text-decoration: underline;"><strong>not</strong></span> buy a gun, let all the zombies in the house and once they are fully inside knife them. Then repair all the barricades and let them in again in round 2 and repeat. (you can do it for round 3 as well but we do not advise it) This tactic gives you maximum points and can also let you get things like; maximum ammo, nuke, double points and instant kill.</li>
<li>When hell hounds appear in the house go into a room with 1 entrance, this stops you from being attacked from behind. It is <strong>strongly</strong> recommended that you have a weapon from the magic box by this time. The ideal weapons for hell hounds are fast reloading weapons which can kill quickly like Thompsons or heavy machine guns with lots of bullets and a lot of fire power. By the way, the last hell hound always drops the maximum ammo upgrade, it is best to reload all your guns before picking this up.</li>
<li>After you get the teddy bear in the house you should look up in the sky outside to see where it has gone, a beam will appear above where it has gone to. Once you find out where it has gone to I would say the best place to go to first is the doctors quarters as it only has 2 windows and the front entrance. After staying in doctor&#8217;s quarters for a while go to where the teddy bear went to, you will need better guns for rounds to come. After improving your guns search around the map for all the perks in this order: Juggernog, Speed Cola, Quick Revive and finally Double Tap Root Beer.</li>
</ol>
<p>COD: WaW is a great game in my opinion and I would rate it a mega 5 star and I would also rate the zombie mode a drop dead and very gruesome 5 star. Lastly I&#8217;d  just like to say the new maps that have just come out and the newest zombies are great and even though they are great I didn&#8217;t include them. This is because they have only just come out a few days before I wrote this so I don&#8217;t know enough about them. If you have read this and improved please comment and tell us how well you did. If you think this is bad advice then don&#8217;t bother moaning, you don&#8217;t have to do what we said! Anyway, thanks for reading.</p>
<p><a href="http://www.mattybatty.co.uk/2009/08/04/call-of-duty-world-at-war-tips/">Call of Duty: World at War Tips</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattybatty.co.uk/2009/08/04/call-of-duty-world-at-war-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Your Next Steps</title>
		<link>http://www.mattybatty.co.uk/2009/07/31/php-your-next-steps/</link>
		<comments>http://www.mattybatty.co.uk/2009/07/31/php-your-next-steps/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 11:00:55 +0000</pubDate>
		<dc:creator>MattyBatty</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.mattybatty.co.uk/?p=177</guid>
		<description><![CDATA[Assuming you have read my basic introduction to PHP, you should have a fair understanding of what PHP is, how to write it, and how to assign and manipulate strings and numbers. In this tutorial, I will be teaching you about Arrays, Loops, and &#8216;if&#8230; else&#8230;&#8217; statements. So, let&#8217;s get started.
Arrays
Say you had a big [...]<p><a href="http://www.mattybatty.co.uk/2009/07/31/php-your-next-steps/">PHP &#8211; Your Next Steps</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Assuming you have read my <a title="PHP - The Basics" href="http://www.mattybatty.co.uk/2009/07/24/php-the-basics/" target="_self">basic introduction to PHP</a>, you should have a fair understanding of what PHP is, how to write it, and how to assign and manipulate strings and numbers. In this tutorial, I will be teaching you about Arrays, Loops, and &#8216;if&#8230; else&#8230;&#8217; statements. So, let&#8217;s get started.</p>
<h3>Arrays</h3>
<p>Say you had a big long list of related variables that you needed to store. For example, names of people. You <em>could</em> store them in separate strings, as you learned before, like this:</p>
<pre>&lt;?php
$name1 = "Matt";
$name2 = "Harry";
$name3 = "Bill";
$name4 = "John";
?&gt;</pre>
<p>However, doing this makes it difficult for them to interact with each other and makes looping through them all tricky. These problems can be solved by using an array. An array uses &#8216;keys&#8217; to link the strings together in one variable. There are three types of array: numeric, associative, and multidimensional. I&#8217;ll leave out multidimensional arrays for now, and focus on numeric and associative as these are more common and easier to use. I will use a numeric array in this example, as there is only one factor linking the variables, the fact that they are all names.<span id="more-177"></span></p>
<p>There are two ways of assigning values to an array. The simplest way is to assign all the values in one line, like so:</p>
<pre>&lt;?php
$names = array("Matt", "Harry", "Bill", "John");
?&gt;</pre>
<p>A more complex way, but easier to understand when you look back at your code, is to assign the &#8216;keys&#8217; yourself:</p>
<pre>&lt;?php
$names[0] = "Matt";
$names[1] = "Harry";
$names[2] = "Bill";
$names[3] = "John";
?&gt;</pre>
<p>Remember: Arrays start at 0, not 1!</p>
<p>In associative arrays, you assign your own keys, like this:</p>
<pre>&lt;?php
$ages = array("Matt"=&gt;20, "Harry"=&gt;30, "Bill"=&gt;35, "John"=&gt;55);
?&gt;</pre>
<p>Or like this:</p>
<pre>&lt;?php
$ages['Matt'] = 20;
$ages['Harry'] = 30;
$ages['Bill'] = 35;
$ages['John'] = 55;
?&gt;</pre>
<p>Easy! And it&#8217;s just as easy to access your arrays, whether it&#8217;s numeric or associative, you access the value using the array name and the key. For example:</p>
<pre>&lt;?php
echo $names[2]; //Will echo 'Bill'
echo $ages['John']; //Will echo '55'

echo $ages[$names[1]]; //Will echo '20' (Although this isn't good practice...)
?&gt;</pre>
<p>But what if you want to solve the original problem of looping through the array&#8230; that&#8217;s where loops come in!</p>
<h3>Loops</h3>
<p>Before we move onto looping through arrays, I&#8217;ll teach you some of the more basic loops in PHP. The &#8216;while&#8217; loop is the most basic loop. It takes one condition and repeats a block of code for as long as that condition is true. You can use this in many ways. For example, you could write out a times table:</p>
<pre>&lt;?php
$table = 5;
$x = 1;
while($x&lt;=12)
   {
   $result = $table*$x;
   echo $result . "&lt;br /&gt;";
   $x++;
   }
?&gt;</pre>
<p>This code would produce:</p>
<pre>5
10
15
20
25
30
35
40
45
50
55
60</pre>
<p>Let me explain, we first set the value of $table to the times table we want to write out, in this case &#8216;5&#8242;. We then initialise $x as &#8216;1&#8242;, to make sure we start the times table from 1. Then, the loop; we say while $x is less than or equal to 12, do this code. This means that we will start the 5 times table at 1 and end at 12. Inside the loop, we put the code which produces the output. We multiply $x by the $table then echo it, along with a line break so it&#8217;s clearer. Finally, we increment $x so it is one more than last time to continue the table. When $x reaches 13, the loop stops. Easy, right?</p>
<p>Well, there&#8217;s an easier way! The &#8216;for&#8217; loop is harder to write but can save a few precious lines of code. The same output as before can be produced from this code:</p>
<pre>&lt;?php
$table = 5;
for($x = 1; $x&lt;=12; $x++)
   {
   $result = $table*$x;
   echo $result;
   }
?&gt;</pre>
<p>In this loop, the initialising and the incrementing is put in when we write the loop condition. This clears up the code inside the loop and enables it to be more easily understood. However, in some cases, &#8216;while&#8217; loops are better than &#8216;for&#8217; loops, so keep that in mind.</p>
<p>The final loop is the &#8216;foreach&#8217; loop, as the name implies, this loop is used to loop through all the values in an array. We&#8217;ll use our $ages array from earlier along with the &#8216;foreach&#8217; loop to create a table of people and their ages.</p>
<pre>&lt;?php
echo "&lt;table&gt;";
echo "&lt;th&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Age&lt;/td&gt;&lt;/th&gt;";
foreach($ages as $name=&gt;$age)
   {
   echo "&lt;tr&gt;&lt;td&gt;" . $name . "&lt;/td&gt;&lt;td&gt;" . $age . "&lt;/td&gt;&lt;/tr&gt;";
   }
echo "&lt;/table&gt;";
?&gt;</pre>
<p>We start the loop by writing $ages as $name=&gt;$age, this means that PHP takes the values one at a time, puts the key in $name and the value in $age, then starts the loop. This happens with each value until there are no more, then the loop stops.</p>
<p>So&#8230; that&#8217;s it, you know how to assign and access variables in arrays, loop through simple values using &#8216;while&#8217; and &#8216;for&#8217;, and how to loop through arrays using &#8216;foreach&#8217;. Let&#8217;s move on&#8230;</p>
<h3>If&#8230; Else&#8230;</h3>
<p>The &#8216;if&#8230; else&#8230;&#8217; statement is used to execute different blocks of code depending on whether a condition is true. This could be used to check somebody&#8217;s answers from a quiz question, and display a message depending on whether they got it correct or not.</p>
<pre>&lt;?php
$answer = $_POST['answer'];
if($answer == "football")
   {
   echo "&lt;p&gt;You are correct!&lt;/p&gt;";
   }
else
   {
   echo "&lt;p&gt;Incorrect, try again!&lt;/p&gt;";
   }
?&gt;</pre>
<p>It is a very simple statement to use, and can often be used without the &#8216;else&#8230;&#8217; if you are displaying something only if a condition is true. However, it can be made more complex with the &#8216;elseif&#8230;&#8217; part, allowing another condition to be checked if the first is false. For example:</p>
<pre>&lt;?php
$answer = $_POST['answer'];
if($answer == "football")
   {
   echo "&lt;p&gt;You are correct!&lt;/p&gt;";
   }
elseif($answer = "rugby")
   {
   echo "&lt;p&gt;Almost right... think harder!&lt;/p&gt;";
   }
else
   {
   echo "&lt;p&gt;Totally wrong, try again!!&lt;/p&gt;";
   }
?&gt;</pre>
<p>Now, with your knowledge of variables, operators, arrays, loops, and statements, you should be capable of producing a simple web application. Why not give it a go while you&#8217;re waiting for the next edition, where you will learn about functions, how to use them, and how to write your own. Make sure you don&#8217;t miss it by subscribing to <a title="My RSS Feed" href="http://www.mattybatty.co.uk/feed/" target="_self">my RSS feed</a>.</p>
<p>Also, if you missed last weeks article, <a title="PHP - The Basics" href="http://www.mattybatty.co.uk/2009/07/24/php-the-basics/" target="_self">take a look</a>. You never know, you might forget something basic one day!</p>
<p><a href="http://www.mattybatty.co.uk/2009/07/31/php-your-next-steps/">PHP &#8211; Your Next Steps</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattybatty.co.uk/2009/07/31/php-your-next-steps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; The Basics</title>
		<link>http://www.mattybatty.co.uk/2009/07/24/php-the-basics/</link>
		<comments>http://www.mattybatty.co.uk/2009/07/24/php-the-basics/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 18:52:49 +0000</pubDate>
		<dc:creator>MattyBatty</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[notepad]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.mattybatty.co.uk/?p=138</guid>
		<description><![CDATA[PHP has grown from nothing to become one of the most popular languages on the web. This is mainly because of it&#8217;s simple syntax, easy usage, and seamless integration with MySQL and other databases. It&#8217;s also free, which makes it a great tool for developers when designing interactive and
dynamic content. In fact, my blog is [...]<p><a href="http://www.mattybatty.co.uk/2009/07/24/php-the-basics/">PHP &#8211; The Basics</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></description>
			<content:encoded><![CDATA[<div id="attachment_143" class="wp-caption alignright" style="width: 147px"><img class="size-full wp-image-143 " title="PHP Logo" src="http://www.mattybatty.co.uk/wp-content/uploads/2009/07/php-logo.png" alt="PHP Logo" width="137" height="72" /><p class="wp-caption-text">PHP Logo</p></div>
<p>PHP has grown from nothing to become one of the most popular languages on the web. This is mainly because of it&#8217;s simple syntax, easy usage, and seamless integration with MySQL and other databases. It&#8217;s also free, which makes it a great tool for developers when designing interactive and</p>
<p>dynamic content. In fact, my blog is powered by the open-source software <a title="WordPress.org" href="http://www.wordpress.org/" target="_blank">WordPress.org</a>, which is written in PHP.</p>
<h3>What is this &#8216;PHP&#8217; thing?</h3>
<p>You may be thinking &#8220;wow, it sounds great, but what is it?&#8221;. So here are a few points about PHP:</p>
<ul>
<li>PHP stands for <strong>P</strong>HP: <strong>H</strong>ypertext <strong>P</strong>reprocessor (It&#8217;s a bit of a paradoxical name if you ask me!)</li>
<li>PHP is a <strong>server-side</strong> scripting language, which means the scripts are executed on the server &#8211; before the user sees any output. (This is similar to ASP.net)</li>
<li>The opposite of <strong>server-side</strong> is <strong>client-side</strong>. JavaScript is a client-side scripting language.</li>
<li>Although PHP is free and open source, you need a server to run PHP, you can&#8217;t just access it in your browser. Common servers include <a title="Apache HTTP Server" href="http://httpd.apache.org/" target="_blank">Apache</a> and <a title="PHP on IIS" href="http://php.iis.net/" target="_blank">Microsoft&#8217;s IIS</a>.</li>
<li>PHP files have the extension .php / .php3 / .phtml</li>
</ul>
<h3>What do I need?</h3>
<p>To be honest, you don&#8217;t really need much at all! A simple text editor such as NotePad or TextEdit will suffice. I use NotePad++ for various reasons, outlined in my <a title="My NotePad++ Review" href="http://www.mattybatty.co.uk/2009/07/20/notepad-review/" target="_self">review</a>, but mainly because of it&#8217;s syntax highlighting. You could also try <a title="NotePad2" href="http://www.flos-freeware.ch/notepad2.html" target="_blank">NotePad2</a> for a more lightweight option.</p>
<p>Also, as I mentioned earlier, you need a webserver to parse the script. This means you will need to host your files somewhere. This could be locally, using a package such as <a title="XAMPP - Server Package" href="http://www.apachefriends.org/en/xampp.html" target="_blank">XAMPP</a>, or you could buy hosting, but make sure they offer PHP support. (Most hosts will, as PHP is free and open source.)</p>
<p>Got all that? Good, let&#8217;s start writing some code!<span id="more-138"></span></p>
<h3>Writing your PHP</h3>
<p>PHP has a very simple syntax, and is written directly into your HTML, in blocks of code. A block starts with&#8230;</p>
<pre>&lt;?php</pre>
<p>&#8230;and ends with&#8230;</p>
<pre>?&gt;</pre>
<p>Inside the PHP block, you put your code. Here is a simple snippet which writes the phrase &#8220;Hello World&#8221; into the HTML page.</p>
<pre>&lt;html&gt;
&lt;body&gt;

&lt;?php
echo "Hello World";
?&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Notice that the &#8220;echo&#8221; statement ends with a semi-colon, if I had forgotten this, the script would have triggered a syntax error. Every statement <strong>must</strong> end with a semi-colon.</p>
<p>I could also add a comment into this script, to help people understand what the script is doing. Comments can be written on one line by using //, or on multiple lines using /* and */, like so&#8230;</p>
<pre>&lt;html&gt;
&lt;body&gt;

&lt;?php

/*
This script writes 'Hello World' to the document.
This was written by MattyBatty.
This is written in PHP.
This is a comment.
*/

echo "Hello World"; //Writes 'Hello World'

?&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<h3>Variables, Strings and Operators!</h3>
<p>Variables is the general name for Text Strings, Numbers and Arrays. All variables in PHP are accessed with the $ symbol. For example, to assign the string &#8220;Hello&#8221; to the variable $greeting, I would do this:</p>
<pre>&lt;?php
$greeting = "Hello";
?&gt;</pre>
<p>Make sure you remember the quotation marks, this is what tells PHP it is a <strong>string</strong>. Once it&#8217;s set, you can then access this variable and echo it like this:</p>
<pre>&lt;?php
echo $greeting;
?&gt;</pre>
<p>See, it&#8217;s simple really! Just like the &#8220;Hello World&#8221; example, but we replace the text with a variable name. It&#8217;s almost identical for numbers too, just one tiny difference. Numbers don&#8217;t need quotation marks when assigning them. So if I wanted to assign the number &#8216;10&#8242; to $number, this is what I would write:</p>
<pre>&lt;?php
$number = 10;
?&gt;</pre>
<p>Got it? You&#8217;re almost there, there are just a few rules you should be aware of:</p>
<ul>
<li>Variable names can only contain letters, numbers, and underscores.</li>
<li>Variable names <strong>must</strong> start with a letter or an underscore, not a number!</li>
<li>No spaces allowed in the name, use underscores or capitalisation instead. (eg. <em>$variable_name </em>or <em>$variableName</em>.)</li>
</ul>
<p>Well done, you now know how to assign and echo variables, but what&#8217;s the fun in that, you want to do something with your variable! There are several hundred functions and tricks you could do with them. I&#8217;ll just teach you the most important ones.</p>
<p>You can join strings together using the &#8211; wait for it &#8211; concatenation operator (full stop) like so&#8230;</p>
<pre>&lt;?php
$string1 = "Hello";
$string2 = "World";
$string3 = $string1 . " " . $string2; //$string3 is now "Hello World"
?&gt;</pre>
<p>Another important function is strlen(). This returns the length of the string. For example, strlen(&#8220;MattyBatty&#8221;) would return &#8216;10&#8242;.</p>
<p>There are also lots of operators for numbers. These are the main ones&#8230;</p>
<ul>
<li>Addition (+)</li>
<li>Subtraction (-)</li>
<li>Multiplication (*)</li>
<li>Division (/)</li>
</ul>
<p>For example, to divide 10 by 2, I would do the following:</p>
<pre>&lt;?php
$result = 10/2;
echo $result; //This would echo '5'
?&gt;</pre>
<p>So&#8230; that&#8217;s it, you&#8217;ve reached the end of this brief introduction to PHP. Come back next week for another PHP tutorial in which we will be discovering arrays, loops, if&#8230; else&#8230; statements and more. Thanks for reading!</p>
<p>P.S. To make sure you don&#8217;t miss the next one, why not <a title="My RSS Feed" href="http://www.mattybatty.co.uk/feed/" target="_self">subscribe to my RSS feed</a>!</p>
<p><a href="http://www.mattybatty.co.uk/2009/07/24/php-the-basics/">PHP &#8211; The Basics</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattybatty.co.uk/2009/07/24/php-the-basics/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Using OO-PHP To Connect To A Database</title>
		<link>http://www.mattybatty.co.uk/2009/07/20/using-oo-php-to-connect-to-a-database/</link>
		<comments>http://www.mattybatty.co.uk/2009/07/20/using-oo-php-to-connect-to-a-database/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 17:10:43 +0000</pubDate>
		<dc:creator>MattyBatty</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.mattybatty.co.uk/?p=85</guid>
		<description><![CDATA[With OO-PHP, you can dramatically speed up the coding process, and re-use code much more effectively. OO-PHP stands for Object Oriented PHP. This means it uses objects, which are collections of properties and methods, rather that a bunch of variables and functions.
Also, as the object is stored in an external file, it can be accessed [...]<p><a href="http://www.mattybatty.co.uk/2009/07/20/using-oo-php-to-connect-to-a-database/">Using OO-PHP To Connect To A Database</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></description>
			<content:encoded><![CDATA[<p>With OO-PHP, you can dramatically speed up the coding process, and re-use code much more effectively. OO-PHP stands for Object Oriented PHP. This means it uses objects, which are collections of properties and methods, rather that a bunch of variables and functions.</p>
<p>Also, as the object is stored in an external file, it can be accessed from any of your pages and used anywhere on your site. This makes objects especially useful. A good example of this is using an object to connect to and interact with a database. In this example, I will use MySQL; but the beauty of objects is that you can change that one file and all the pages will be updated, which makes changing between databases easy!<span id="more-85"></span></p>
<p>Now, if you were using procedural code, you would connect to MySQL and perform a query like this:</p>
<pre><code>$dbhost   = "localhost";
$dbuser   = "user";
$dbpass   = "pass";
$dbname   = "dbname";
$con      = mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not CONNECT: " . mysql_error());
$dbselect = mysql_select_db($dbname, $con) or die("Could not SELECT DB: " . mysql_error());
$sql      = "SELECT * FROM tbl_name WHERE col_name = 'foo'";
$query    = mysql_query($sql) or die("Could not EXECUTE QUERY: " . mysql_error());

while($row = mysql_fetch_array($query))
 {
 echo $row['row_name'];
 }
mysql_close($con);</code></pre>
<p>That seems VERY long, doesn&#8217;t it? If you use OOP, you could perform exactly the same connection, query, fetch and close just by doing this:</p>
<pre><code>$db     = new MySQL;
$result = $db-&gt;query("SELECT * FROM tbl_name WHERE col_name = 'foo'");
while($row = $result-&gt;fetch())
 {
 echo $row['row_name'];
 }
$db-&gt;close();</code></pre>
<p>That&#8217;s a lot nicer, isn&#8217;t it? But how can it be that easy? Well, the secret is in the MySQL class. You see this line here:</p>
<pre><code>$db = new MySQL;</code></pre>
<p>That&#8217;s the line that creates an instance of the MySQL class. What is the MySQL class? Well, it looks like this:</p>
<pre><code>class MySQL
 {
 var $dbName;
 var $dbConn;
 var $dbSelect;
 var $dbQuery;
public function MySQL($dbName="default_db_name")
 {
 $this-&gt;dbName = $dbName;
 $this-&gt;connectToDb();
 }
 private function connectToDb()
 {
 $this-&gt;dbConn = mysql_connect("localhost", "user", "pass");
 if(!$this-&gt;dbConn)
 {
 die("Could not CONNECT: " . mysql_error());
 }
 $this-&gt;dbSelect = mysql_select_db($this-&gt;dbName, $this-&gt;dbConn);
 if(!$this-&gt;dbSelect)
 {
 die("Could not SELECT DB: " . mysql_error());
 }
 }
 public function query($sql)
 {
 $this-&gt;theQuery = mysql_query($sql);
 if(!$this-&gt;theQuery)
 {
 die("Could not EXECUTE QUERY: " . $sql . " - " . mysql_error());
 }
 return new MySQLResult($this, $this-&gt;theQuery);
 }
 public function close()
 {
 mysql_close($this-&gt;dbConn);
 }
 }</code></pre>
<p>The class is the bit that does all the magic, it connects to the server, selects the database, and executes the queries. It also does all the error-catching and &#8220;tidying up&#8221;.</p>
<p>When it is finished with the query, it passes it to the MySQLResult class, which handles the processing of the results. The MySQLResult class looks like this:</p>
<pre><code>class MySQLResult
 {
 var $MySQL;
 var $theQuery;
 public function MySQLResult($MySQL, $theQuery)
 {
 $this-&gt;MySQL = $MySQL;
 $this-&gt;theQuery = $theQuery;
 }
 public function fetch()
 {
 if ($row = mysql_fetch_array($this-&gt;theQuery))
 {
 return $row;
 }
 }</code></pre>
<p>Together, these two classes make it much easier to connect to and interact with the database, and can make your code much shorter. This causes less bugs and there are less spelling mistakes and syntax errors. This is why I believe OO-PHP is the way to go, and these classes are ready to go as they are, they only need changing so the username and password work for your database, and you&#8217;re off! Feel free to use them and speed up your coding!</p>
<p><a href="http://www.mattybatty.co.uk/2009/07/20/using-oo-php-to-connect-to-a-database/">Using OO-PHP To Connect To A Database</a> is originally from: <a href="http://www.mattybatty.co.uk">MattyBatty.co.uk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattybatty.co.uk/2009/07/20/using-oo-php-to-connect-to-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
