<?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>Ideal Websites Blog</title>
	<atom:link href="http://www.idealwebsites.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.idealwebsites.co.uk/blog</link>
	<description>News, articles and ideas from web development agency Ideal Websites Ltd.</description>
	<lastBuildDate>Tue, 04 Oct 2011 10:29:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Copia CMS links with LinkedIn</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/10/04/copia-cms-links-with-linkedin/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/10/04/copia-cms-links-with-linkedin/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 10:29:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Company Updates]]></category>
		<category><![CDATA[Industry News]]></category>
		<category><![CDATA[copia]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[new features]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=341</guid>
		<description><![CDATA[We have been adding features to Copia CMS, and amongst the new features is integration with the business social networking/CV site, LinkedIn, using their Apply With LinkedIn button feature. Now users can easily post LinkedIn jobs ads on their site, and Copia will sort out the more intricate details, needing just the API key and [...]]]></description>
			<content:encoded><![CDATA[<p>We have been adding features to <a href="http://www.copiacms.co.uk/" target="_blank">Copia CMS</a>, and amongst the new features is integration with the business social networking/CV site, <a href="http://www.linkedin.com" target="_blank">LinkedIn</a>, using their <a href="https://developer.linkedin.com/plugins/apply" target="_blank">Apply With LinkedIn</a> button feature.</p>
<p><a href="http://www.idealwebsites.co.uk/blog/wp-content/uploads/2011/10/LinkedIn-button.png"><img class="alignnone size-full wp-image-343" style="border: 3px solid black;" title="LinkedIn button" src="http://www.idealwebsites.co.uk/blog/wp-content/uploads/2011/10/LinkedIn-button.png" alt="" width="291" height="180" /></a></p>
<p>Now users can easily post LinkedIn jobs ads on their site, and Copia will sort out the more intricate details, needing just the API key and Company ID from the social networking site, and users can set the job title, location, email etc. via the CMS (see below).</p>
<p><a href="http://www.idealwebsites.co.uk/blog/wp-content/uploads/2011/10/LinkedIn-admin.png"><img class="alignnone size-full wp-image-344" title="LinkedIn admin" src="http://www.idealwebsites.co.uk/blog/wp-content/uploads/2011/10/LinkedIn-admin.png" alt="" width="418" height="437" /></a></p>
<p>This feature appears in the CMS along with the WYSIWYG editor, Google Maps module and News Article features, and is a quick and easy way to post new career opportunities on your site, taking advantage of LinkedIn&#8217;s ever increasing popularity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/10/04/copia-cms-links-with-linkedin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error Handling Part 2</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/08/31/error-handling-part-2/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/08/31/error-handling-part-2/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 15:28:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[fatal error]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[triggers]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=334</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. As you will know, there are a number of reasons you could get an error in PHP. However, sometimes you will want something to be flagged as an error if it&#8217;s going [...]]]></description>
			<content:encoded><![CDATA[<div class="note"><strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.</div>
<p>As you will know, there are a number of reasons you could get an error in PHP. However, sometimes you will want something to be flagged as an error if it&#8217;s going to cause problems in how your script works further down the line, and for this we can use the <em>trigger_error()</em> function within an <em>if()</em> statement to bring up an error.</p>
<p>For example, consider the following code:</p>
<p><code>&lt;?php</p>
<p>function numberCheck($number) {</p>
<p>// function checks to see if a number is a whole<br />
// trigger a warning if not<br />
	if (is_float($number)) {<br />
		trigger_error("$number is not a whole number", E_USER_WARNING);<br />
	}</p>
<p>// trigger a fatal error if number is negative<br />
	if ($number < 0) {<br />
		trigger_error("$number is a negative number!", E_USER_ERROR);<br />
	}<br />
}</p>
<p>// error handler</p>
<p>function errorHandler($type, $msg, $file, $line, $context) {<br />
	switch ($type) {<br />
	// warning<br />
	case E_USER_WARNING:<br />
		print "Warning: error on line $line of &lt;em>$file&lt;/em>: $msg&lt;br />";<br />
		break;</p>
<p>	// fatal errors<br />
	case E_USER_ERROR:<br />
		die("Fatal error on line $line of &lt;em>$file&lt;/em>: $msg&lt;br />");<br />
		break;</p>
<p>	// notices - don't worry about it<br />
	default:<br />
		break;<br />
	}<br />
}</p>
<p>set_error_handler('errorHandler');</p>
<p>numberCheck(20);<br />
numberCheck(6.2);<br />
numberCheck(-10);</code></p>
<p>Here, the initial function creates a warning (E_USER_WARNING) if the the number isn&#8217;t an integer (whole number), and a fatal error (E_USER_ERROR) if the number is negative. The error then gets processed through to the error handler (as discussed in the last post) and is outputted in an easily legible form. Of course, when testing these error handlers, it is important to remember that anything that follows a fatal error will not run. It is also possible to create notices, using E_USER_NOTICE.</p>
<p>I was going to discuss exceptions in this post, however, it&#8217;s a fairly big topic and probably warrants its own post, so apologies if this one is a little short, but next time I will go over exceptions, what they are and when to use them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/08/31/error-handling-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error Handling Part 1</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/08/24/error-handling-part-1/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/08/24/error-handling-part-1/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 14:25:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[fatal error]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[warnings]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=329</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. One thing that becomes clear fairly quickly when learning PHP is that you are going to get errors, and sometimes these can be hard to decipher. PHP comes with an error handling [...]]]></description>
			<content:encoded><![CDATA[<div class="note"><strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.</div>
<p>One thing that becomes clear fairly quickly when learning PHP is that you are going to get errors, and sometimes these can be hard to decipher. PHP comes with an error handling API that can be used to identify and resolve errors.</p>
<p>Errors in PHP come in three basic forms:</p>
<ul>
<li><strong>Notices</strong> are minor errors that will not break the site, such as an undefined variable, that by default will not display the error the user.</li>
<li><strong>Warnings</strong> are a slightly bigger deal, they will not abort the code but they will display an error message to the user by default. An example of a warning is if you were to try and <em>include()</em> a file that didn&#8217;t exist.</li>
<li><strong>Fatal errors</strong> are critical errors, and will abort the code i.e. any code that follows will not be run. Fatal errors can occur when calling a function that does not exist, or if there are syntax errors such as a missing semi-colon.</li>
</ul>
<p>What&#8217;s cool about these errors is that they create a set of variables that are ready to be used in conjunction with the <em>set_error_handler()</em> function to create front end error messages.</p>
<p>In order to do this, you must create a function which determines what to do with the following variables: $type, $msg, $file, $line, $context &#8211; all of which are fairly self-explanatory.</p>
<p>So for example, consider the following code:</p>
<p><code>&lt;?php<br />
set_error_handler('errormsg');<br />
$string = 'this will break the code';</p>
<p>// create a warning by only giving the explode() function one parameter</p>
<p>explode($string);</p>
<p>function errormsg($type, $msg, $file, $line, $context) {<br />
    echo "&lt;h1>ERROR!!!</h1>
<p>";<br />
    echo "Something messed up up, please contact "?>&lt;a href="mailto:youname@youremail">me</a><br />
    <?php echo "to report this error&lt;br />";<br />
    echo "Please quote the following:&lt;br />";<br />
    echo "Error code: ".$type."&lt;br /><br />
    Error message: ".$msg."&lt;br /><br />
    Script name and line number of error: ".$file.":".$line."&lt;br />";<br />
    $variable_state = array_pop($context);<br />
    echo "Variable state when error occured: ";<br />
    print_r($variable_state);<br />
    }</code></p>
<p>Here, the details of the error are pulled and defined by the errormsg() function, and rearranged in a manner that will make (at least some) sense to the user. This works for warnings, but not for fatal errors, which I will go over next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/08/24/error-handling-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimpleXML</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/08/08/simplexml/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/08/08/simplexml/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 15:08:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[markup language]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=319</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. XML stands for Extensible Markup Language and is used for encoding-documents in machine-readable form. It is the basis for many languages and programmes that you are likely already familiar with, such as [...]]]></description>
			<content:encoded><![CDATA[<div class="note"><strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.</div>
<p><em>XML</em> stands for <em>Extensible Markup Language</em> and is used for encoding-documents in machine-readable form. It is the basis for many languages and programmes that you are likely already familiar with, such as Microsoft Office, RSS and HTML. Like HTML, it is all based around tags, using less-than and greater-than symbols. The key difference is that, in XML, you define your own tags and then work out what to do with them later, and we can do this using PHP 5 and an extension known as <em>SimpleXML</em>.</p>
<p>SimpleXML works by converting XML documents into objects, and turning the elements within the file into object properties, free to be accessed by standard object notation. It is worth noting again that this is an <em>extension</em> of PHP, and therefore your PHP build must support it.</p>
<p>To get you started, here is a basic XML script, let&#8217;s call it &#8216;film.xml&#8217;:</p>
<p><code>&lt;?xml version="1.0"?><br />
&lt;film><br />
	&lt;title>Apocalypse Now&lt;/title><br />
	&lt;setting>the Vietnam War&lt;/setting><br />
	&lt;characters><br />
		&lt;protagonist>Captain Willard&lt;/protagonist><br />
		&lt;antagonist>Col. Kurtz&lt;/antagonist><br />
	&lt;/characters><br />
	&lt;release>1979&lt;/release><br />
	&lt;director>Francis Ford Coppola&lt;/director><br />
&lt;/film></code></p>
<p>As previously stated, we can use SimpleXML to pull information from this file, and as the name suggests, it&#8217;s really quite simple:</p>
<p><code>&lt;?php</p>
<p>$file = "film.xml";</p>
<p>//load file<br />
$xml = simplexml_load_file($file);</p>
<p>//access data<br />
echo "Film: ".$xml->title."&lt;br />";<br />
echo "Release date: ".$xml->release."&lt;br />";<br />
echo "The film is about ".$xml->characters->protagonist." and ".$xml->characters->antagonist." in ".$xml->setting;</code></p>
<p>As you can see above, we first load the xml file using the <em>simplexml_load_file()</em> function, which parses the XML file into a PHP object, with each element becoming a property of that object.</p>
<p>On top of this, it is also to work in the other direction, and write information into the file, like so:</p>
<p><code>&lt;?php</p>
<p>$file = "film.xml";<br />
$xml = simplexml_load_file($file);</p>
<p>// modify the data<br />
$xml->title = "Back to the Future";<br />
$xml->setting = "the 1950s";<br />
$xml->characters->protagonist = "Marty McFly";<br />
$xml->characters->antagonist = "Biff";<br />
$xml->release = "1985";<br />
$xml->director = "Robert Zemeckis";</p>
<p>// write new data into the file<br />
file_put_contents($file, $xml->asXML());</code></p>
<p>One thing you will need to be sure of is that, since you are using PHP to change a file, the permissions for the file must be set to public (777).</p>
<p>So now you know the basics of how to pull information from an XML file using PHP, and how to put it back in again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/08/08/simplexml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpMyAdmin</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/07/25/phpmyadmin/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/07/25/phpmyadmin/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 16:28:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=315</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. As previously mentioned, phpMyAdmin is an online application for managing your MySQL databases using PHP. It is very powerful, and can create, modify or delete databases, tables, fields or rows of your [...]]]></description>
			<content:encoded><![CDATA[<div class="note"><strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.</div>
<p>As previously mentioned, phpMyAdmin is an online application for managing your MySQL databases using PHP. It is very powerful, and can create, modify or delete databases, tables, fields or rows of your databases, by generating and executing MySQL statements. The first version to be released was version 0.9.0 in September 1998, and is, at the time of writing, on version 3.4.0 &#8211; released in May 2011.</p>
<p>To install phpMyAdmin, first you must <a href="http://www.phpmyadmin.net/home_page/downloads.php">download it from the website</a>. Uncompress the folders, including subdirectories, into your webserver&#8217;s document root (or your local machine, if you intend to work locally and upload via FTP later). You must ensure that the scripts are set to have the appropriate owner, then you can configure your installation. You can do this by editing the <em>config.inc.php</em> file, but now you also have the option to use an inbuilt setup wizard by creating a folder, <em>config</em> in the phpMyAdmin directory, and then going to <em>http://your-server/where-phpmyadmin-is/setup/</em> in your browser. After completing the wizard, you should be able to access phpMyAdmin through your browser. Bear in mind that, as of yet, there are no security settings. For more information about securing your databases, <a href="http://www.phpmyadmin.net/documentation/#authentication_modes">see the official documentation</a>.</p>
<p>Now that you have set up phpMyAdmin, you should see a list of your databases down the left hand side, and a main menu at the top. By selecting the databases from the left, you can view or edit them. You can use the <em>SQL</em> tab in the main menu to run MySQL scripts, and use the Export and Import tabs to generate scripts, allowing you transfer data or tables between databases easily, which is can be very useful if you are running multiple sites from the same content management system.</p>
<p>That&#8217;s all for phpMyAdmin, but there is a lot more to cover, so I would recommend <a href="http://www.phpmyadmin.net/documentation/">checking the documentation</a> for further how-tos.</p>
<p>Next time there will be some actual PHP code, I promise.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/07/25/phpmyadmin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/07/18/mysql/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/07/18/mysql/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 15:38:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[structured query language]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=296</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. PHP is a fantastic web programming language, but much in the way that to get the most out of HTML, it&#8217;s a good idea to get into CSS, to get the most [...]]]></description>
			<content:encoded><![CDATA[<div class="note"><strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.</div>
<p>PHP is a fantastic web programming language, but much in the way that to get the most out of HTML, it&#8217;s a good idea to get into CSS, to get the most out of PHP, it&#8217;s a good idea to get acquainted with <em>MySQL</em>.</p>
<p>MySQL is a <em>structured query language</em>, a type of language used for managing data in a &#8216;relational database model&#8217;, i.e. a database where both the data and the relationships between the various data is stored in tables. It is the backbone of many sites where content is updated on a regular basis, including social networking sites like Facebook, message boards, and content management systems such as WordPress.</p>
<p>As an example, if you were to create a new post on a WordPress-powered blog, the moment WordPress automatically saves a draft, the content of the post (including the title, tags, categories and post settings) get inserted into the MySQL database. If this post is published, or if you click &#8216;Preview post&#8217;, PHP will request this information from the database and print it out into the browser, using the template set out by the PHP, HTML and CSS.</p>
<p>The tables themselves look like ASCII images, in the sense that they are a drawing made up of text characters:</p>
<p><a href="http://www.idealwebsites.co.uk/blog/wp-content/uploads/2011/07/Screen-shot-2011-07-18-at-12.08.20.png"><img class="size-full wp-image-300 alignnone" title="MySQL table example" src="http://www.idealwebsites.co.uk/blog/wp-content/uploads/2011/07/Screen-shot-2011-07-18-at-12.08.20.png" alt="" width="210" height="140" /></a></p>
<p>To interact with the MySQL database, we can embed SQL into our PHP scripts, for example:</p>
<div class="note"><strong>Note:</strong> The following code has not been tested and may not be completely correct/valid</div>
<p><code>&lt;?php</code></p>
<p><code>mysql_query("CREATE DATABASE peopledb;</p>
<p>CREATE TABLE 'names' (<br />
'id' int(11) NOT NULL auto_increment,<br />
'firstname' varchar(255) NOT NULL default '',<br />
'surname' varchar(255) NOT NULL default '',<br />
PRIMARY KEY ('id')<br />
) TYPE=MyISAM;</p>
<p></code></p>
<p><code>INSERT INTO 'names' VALUES (1, 'John', 'Smith');<br />
INSERT INTO 'names' VALUES (2, 'Joe', 'Bloggs');<br />
INSERT INTO 'names' VALUES (3, 'Jane', 'Doe');<br />
INSERT INTO 'names' VALUES (4, 'Mrs', 'Marple');<br />
INSERT INTO 'names' VALUES (5, 'Homer', 'Simpson');<br />
INSERT INTO 'names' VALUES (6, 'Honey', 'Monster');");</code></p>
<p>As you may have guessed, the first section of the query is creating the database. <em>MyISAM</em> is the default storage engine used by MySQL. The second section is inputting the information into the table.</p>
<p>There is a LOT more to say about MySQL and using this information alone will not be enough to use it in your project. An extra snippet of code you will need to familiarise yourself is used to connect your site to the database:</p>
<p><code>&lt;?php<br />
$host = "localhost";<br />
$user = "test";<br />
$pass = "test";<br />
$db = "peopledb";</code></p>
<p>These variables will depend on how the website is set up, i.e. where the site is hosted, what the username is, what the password is and what the database is called. Fortunately, a variety of open source applications have been set up to make this process a lot easier and next time I will go over one of the best ones, <em>phpMyAdmin</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/07/18/mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More OOP</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/07/13/more-oop/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/07/13/more-oop/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 11:10:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php basics]]></category>
		<category><![CDATA[php help]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=289</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. For this PHP Basics post, I will be borrowing, but editing, some of the code I used in the last post, An introduction to OOP &#8211; specifically adding a &#8216;weight&#8217; property, and [...]]]></description>
			<content:encoded><![CDATA[<div class="note">
<strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.
</div>
<p>For this PHP Basics post, I will be borrowing, but editing, some of the code I used in the last post, <em><a href="http://www.idealwebsites.co.uk/blog/2011/07/11/an-introduction-to-oop/">An introduction to OOP</a></em> &#8211; specifically adding a &#8216;weight&#8217; property, and an &#8216;eat&#8217; method, which will come in useful later on.</p>
<p><code>&lt;?php</p>
<p>// In this case I'm going to use Simpsons characters</p>
<p>// define class<br />
class Character {<br />
	//define properties<br />
	public $name;<br />
	public $age;<br />
	public $job;<br />
	public $weight;</p>
<p>	// now we define the methods<br />
	public function sleep() {<br />
		echo $this->name." is sleeping&lt;br />";<br />
	}<br />
	public function work() {<br />
		echo $this->name." is at work&lt;br />";<br />
    	}<br />
	public function home() {<br />
		echo $this->name." is at home&lt;br />";<br />
	}<br />
	public function eat($lb) {<br />
        	echo $this->name." is eating ".$lb."lb of food&lt;br />";<br />
        	$this->weight += $lb;<br />
    	}<br />
}</p>
<p>// create new object<br />
$homer = new Character;<br />
// define characteristics<br />
$homer->name = "Homer Simpson";<br />
$homer->age = "middle-aged";<br />
$homer->job = "nuclear safety technician";<br />
$homer->weight = 239;</p>
<p>// and again<br />
$marge = new Character;<br />
$marge->name = "Marge Simpson";<br />
$marge->age = "middle-aged";<br />
$marge->job = "listen lady";<br />
$marge->weight = 135;</p>
<p>$bart = new Character;<br />
$bart->name = "Bart Simpson";<br />
$bart->age = "a kid";<br />
$bart->job = "hell raiser";<br />
$bart->weight = 65;</code></p>
<p>The addition of these allow the code to adjust the properties within the class to make them more dynamic. For instance, assuming that weight and eating are inextricably linked, it makes perfect sense that if one of our Characters were to eat a certain amount of food, their weight should increase with it. So now, we can make the Characters &#8220;eat&#8221;:</p>
<p><code>&lt;?php</p>
<p>// retrieve weight property<br />
echo $homer->name." weighs ".$homer->weight."lb&lt;br />";<br />
echo $marge->name." weighs ".$marge->weight."lb&lt;br />";<br />
echo $bart->name." weighs ".$bart->weight."lb&lt;br />";</p>
<p>// call eat function<br />
$homer->eat(5);<br />
$marge->eat(4);<br />
$homer->eat(3);<br />
$bart->eat(5);<br />
$homer->eat(10);</p>
<p>// retrieve new weight<br />
echo $homer->name." now weighs ".$homer->weight."lb&lt;br />";<br />
echo $marge->name." now weighs ".$marge->weight."lb&lt;br />";<br />
echo $bart->name." now weighs ".$bart->weight."lb";</code></p>
<p>What we should get from this is the following:</p>
<p><em>Homer Simpson weighs 239lb<br />
Marge Simpson weighs 135lb<br />
Bart Simpson weighs 65lb<br />
Homer Simpson is eating 5lb of food<br />
Marge Simpson is eating 4lb of food<br />
Homer Simpson is eating 3lb of food<br />
Bart Simpson is eating 5lb of food<br />
Homer Simpson is eating 10lb of food<br />
Homer Simpson now weighs 257lb<br />
Marge Simpson now weighs 139lb<br />
Bart Simpson now weighs 70lb</em></p>
<p>It is worth noting that with PHP5, a new concept of <em>visibility</em> was introduced into the object model. You may notice in the class definition that the Character properties are all preceded with the word, <em>public</em>. This allows the calling script into the object instances and manipulate them. There are two other options, <em>private</em> and <em>protected</em>, which prevent the script from manipulating the class. The former meaning that the properties can only be accessed by the class that defines it, and the latter meaning that properties can only be accessed within the class, or by inherited and parent classes. However, this is all fairly complicated so I shan&#8217;t go through it just yet.</p>
<p>Next up is an introduction to MySQL databases, a topic which comes with something of a difficulty spike, but is ultimately an incredibly useful tool for PHP programmers, and is essentially what allows many message boards and social networking sites to exist.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/07/13/more-oop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An introduction to OOP</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/07/11/an-introduction-to-oop/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/07/11/an-introduction-to-oop/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 16:18:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=280</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. Last time I spoke about functions, and while there is still a fair bit to say on the matter, I&#8217;m going to move forward a little and talk about OOP, as it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<div class="note">
<strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.
</div>
<p>Last time I spoke about functions, and while there is still a fair bit to say on the matter, I&#8217;m going to move forward a little and talk about <em>OOP</em>, as it&#8217;s a fairly important part of programming, especially in PHP 5 onwards. It stands for &#8216;<em>Object Oriented Programming</em>&#8216;, and is the basis of PHP frameworks such as the Zend Framework.</p>
<p>OOP revolves around <em>classes</em>, <em>objects</em> and <em>methods</em>. A <em>class</em> is a set of program statements that perform a specific tasks, and generally feature both variables and functions. <em>Objects</em> are the specific instances in which classes appear. A <em>method</em> is a predefined function of the object. Once the class has been defined, we can bring it in as much as we like, and each time we bring it in, it is a separate object, and can be affected independently of other objects.</p>
<p>The key point behind object orientated programming is that it is easily updatable and editable. To see OOP in action, see the following example:</p>
<p><code>&lt;?php</p>
<p>// In this case I'm going to use Simpsons characters</p>
<p>// define class<br />
class Character {<br />
	//define properties<br />
	public $name;<br />
	public $age;<br />
	public $job;</p>
<p>	// now we define the methods<br />
	public function sleep() {<br />
		echo $this->name." is sleeping&lt;br />";<br />
	}<br />
	public function work() {<br />
		echo $this->name." is at work&lt;br />";<br />
    	}<br />
	public function home() {<br />
		echo $this->name." is at home&lt;br />";<br />
	}<br />
}</code></p>
<p>Now we can use this class as a template and apply individual characteristics to each object:</p>
<p><code>&lt;?php</p>
<p>// create new object<br />
$homer = new Character;<br />
// define characteristics<br />
$homer->name = "Homer Simpson";<br />
$homer->age = "middle-aged";<br />
$homer->job = "nuclear safety technician";</p>
<p>// and again…<br />
$marge = new Character;<br />
$marge->name = "Marge Simpson";<br />
$marge->age = "middle-aged";<br />
$marge->job = "listen lady";</p>
<p>$bart = new Character;<br />
$bart->name = "Bart Simpson";<br />
$bart->age = "a kid";<br />
$bart->job = "hell raiser";</p>
<p>// then we can pull the methods from each class to make the objects interact</p>
<p>$homer->work();<br />
$homer->sleep();<br />
$marge->home();<br />
$bart->home();<br />
$bart->sleep();</code></p>
<p>You will notice that there are a few functions that don&#8217;t come into play. I will use this same code next time and go over some more things that can be done with object orientating programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/07/11/an-introduction-to-oop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Functions()</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/07/04/functions/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/07/04/functions/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 14:32:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[how do i create a function]]></category>
		<category><![CDATA[php basics]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=273</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. &#8220;Function&#8221; is a word that you will have read a lot if you have been reading this series, or if you have been reading up on PHP elsewhere. A great deal of [...]]]></description>
			<content:encoded><![CDATA[<div class="note">
<strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.
</div>
<p>&#8220;Function&#8221; is a word that you will have read a lot if you have been reading this series, or if you have been reading up on PHP elsewhere. A great deal of what we do in PHP relies on calling functions. For instance, just last week we used the <em>fopen()</em> function to open a file. They&#8217;re easily spotted by the pairs of brackets that sit at the end of them. So it seems odd, then, to do a blog post on functions when we&#8217;re already quite well acquainted with them. It seems odd, that is, until you realise that in PHP, we also have the power to create our own functions.</p>
<p>To give the term a proper definition, a function is a set of statements that can be called from anywhere within the program. This is a massive time saver as it means you can reuse sections for common tasks. A very basic function could look something like this:</p>
<p><code>&lt;?php<br />
function yesYouCan(){<br />
	echo "Yes you can!&lt;br /&gt;";<br />
}<br />
// now we can call this whenever we want<br />
echo "Can I make my own functions?&lt;br /&gt;";<br />
yesYouCan();<br />
echo "Can I kick it?&lt;br /&gt;";<br />
yesYouCan();</code></p>
<p>As I mentioned, this is a very basic function and one that is not of much use to anyone. That is partly down to the fact that all it does is echo out a statement, but it is also because no arguments have been defined. Arguments allow us to bring variables into the equation, and we can also define variables within the function.</p>
<p>For instance, if we were to create a program that said how many biscuits were left in the pack, we could create a <em>biscuits()</em> function like so:</p>
<p><code>&lt;?php<br />
// define the function, with the variables within the brackets<br />
function biscuits($type, $eaten, $total){<br />
	$amount = $total - $eaten;<br />
	echo "&lt;strong&gt;$type:&lt;/strong&gt;&lt;br /&gt;<br />
		$eaten $type biscuits out of $total have been eaten, there are $amount left&lt;br /&gt;";<br />
}</p>
<p>// call out a different result for each pack of biscuits<br />
biscuits('Digestive', 9, 20);</p>
<p>biscuits('Garibaldi', 21, 30);</p>
<p>biscuits('Nice', 2, 25);</code></p>
<p>Naturally, the sky is the limit as to how complex these functions can get (although it is important to remember that the more complex the code is, the slower it will run). These were simple examples, but I will go into detail about more complex functions in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/07/04/functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Files and More PHP</title>
		<link>http://www.idealwebsites.co.uk/blog/2011/06/29/more-files-and-more-php/</link>
		<comments>http://www.idealwebsites.co.uk/blog/2011/06/29/more-files-and-more-php/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 16:07:34 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[file handling]]></category>
		<category><![CDATA[php basics]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://www.idealwebsites.co.uk/blog/?p=269</guid>
		<description><![CDATA[Note: These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer. Last time I closed by showing you how to open a file and separate the lines into an array using the file() function, which can potentially be very useful and opens up [...]]]></description>
			<content:encoded><![CDATA[<div class="note">
<strong>Note:</strong> These posts are part of a series written by an Ideal Websites employee, who is currently training to become a PHP developer.
</div>
<p>Last time I closed by showing you how to open a file and separate the lines into an array using the <em>file()</em> function, which can potentially be very useful and opens up a lot of possibilities. However, sometimes you don&#8217;t want an array but do not want to go through all the effort of opening the file, defining the handle, and reading the file. Thankfully, the <em>file_get_contents()</em> function does exactly this, and is incredibly easy to use, as shown below:</p>
<p><code>&lt;?php<br />
// set the file<br />
$file = 'file.txt';<br />
// read the file<br />
$contents = file_get_contents($file);<br />
echo $contents;</code></p>
<p>Where it gets more interesting, however, is with the <em>include()</em> function. These allow you to pull in other bits of code, which can be used multiple times. So for instance, if you were to create a file for the header:</p>
<p><code>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;&lt;?php echo $title ?&gt;&lt;/title&gt;<br />
&lt;h1&gt;&lt;?php echo $title ?&gt;&lt;/h1&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</code></p>
<p>and then a footer file:</p>
<p><code>&lt;p&gt;Copyright blah blah blah &lt;?php echo date("Y", mktime()); ?&gt;&lt;/p&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p>and called them header.php and footer.php respectively.</p>
<p>Then we can create a script that can pull these two files in to make a complete page:</p>
<p><code>&lt;?php<br />
// define the title<br />
$title = 'The include function';<br />
// include the page header<br />
include('header.php');<br />
?&gt;<br />
&lt;p&gt;Then you put your content here&lt;/p&gt;<br />
&lt;?php<br />
// include the footer<br />
include('footer.php');</code></p>
<p>It is worth noting that there are alternatives to the <em>include()</em> function. There is the <em>require()</em> function, which works in much the same way, except for the fact that if it cannot find the file, it was cause a fatal error, whereas <em>include()</em> will continue to run the script. In addition to these, there are <em>include_once()</em> and <em>require_once()</em> which, predictably, are identical to their counterparts with the exception that they ensure that the file is only pulled in once.</p>
<p>We know how to read and open a file, but of course, writing a file is also possible, using the <em>fwrite()</em> function. This works in much the same way as reading a file &#8211; first you must define the file, then open it, and then write into it, like so:</p>
<p><code>&lt;?php<br />
// set file to write<br />
$file = 'newfile.txt';<br />
// open file, and use the 'w' mode to set it to write<br />
$fh = fopen($file, 'w');<br />
// write to file<br />
fwrite($fh, "This file didn't exist before but now it does");<br />
// close file<br />
fclose($fh);</code></p>
<p>Also like reading a file, there is a shortcut to do so, which was included in PHP 5 &#8211; the <em>file_put_contents() function</em>, as shown below:</p>
<p><code>&lt;?php<br />
// set file to write<br />
$file = 'anotherfile.txt';<br />
// write to file<br />
file_put_contents($file, "I made this file even quicker than the last one!");</code></p>
<p>That&#8217;s all for now, but there is still plenty more you can do with files, such as status checks and uploads which I will go over in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idealwebsites.co.uk/blog/2011/06/29/more-files-and-more-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

