<?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>Syntax Error&#187; php Archives  &#8211; Syntax Error</title>
	<atom:link href="http://www.syntaxerror.org.uk/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.syntaxerror.org.uk</link>
	<description>Parse error: syntax error, unexpected $end in</description>
	<lastBuildDate>Mon, 20 Sep 2010 19:26:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Creating a contact form using classes part 1</title>
		<link>http://www.syntaxerror.org.uk/php/creating-contact-form-classes-part-1/</link>
		<comments>http://www.syntaxerror.org.uk/php/creating-contact-form-classes-part-1/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 19:06:35 +0000</pubDate>
		<dc:creator>clutz</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[contact form]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php mail]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">http://www.syntaxerror.org.uk/?p=15</guid>
		<description><![CDATA[At work I was asked to create an email contact form, heres how I did it.]]></description>
			<content:encoded><![CDATA[<div class='series_toc'><h3>Table of contents for Contact Form</h3><ol><li>Creating a contact form using classes part 1</li></ol></div> <p>Recently I was asked at work to build a PHP email contact form that could do some specific things.</p>
<ul>
<li>Allow the user to choose different departments/emails to send their submission to</li>
<li>Allow the user to input specific things into boxes such as telephone number, order ID</li>
<li>Be easy to extend so a non programmer could add an extra input at a later date</li>
</ul>
<p>Then there were a few things I wanted to do.</p>
<ul>
<li>Use classes to separate logic from layout</li>
<li>Clean and validate all input</li>
</ul>
<p>Now there&#8217;s a lot of websites that show you how to do email forms, but most just send a users email address, name and message via post to a separate PHP file and then compose and email. While this is nice, simple and works it doesn&#8217;t allow for all the things that was asked and I felt should be done.</p>
<p>In part 2 I&#8217;ll show you how I started to build my classes.</p>
 <div class='series_links'> </div>]]></content:encoded>
			<wfw:commentRss>http://www.syntaxerror.org.uk/php/creating-contact-form-classes-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autoloader basics</title>
		<link>http://www.syntaxerror.org.uk/php/autoloader-basics/</link>
		<comments>http://www.syntaxerror.org.uk/php/autoloader-basics/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 20:40:54 +0000</pubDate>
		<dc:creator>clutz</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Autoloader]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[code samples]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://www.syntaxerror.org.uk/?p=6</guid>
		<description><![CDATA[How to make the autoloader function use folders]]></description>
			<content:encoded><![CDATA[<p>Since this is my first post I&#8217;ll keep it nice and simple. While there&#8217;s a perfectly good autoloader <a title="PHP Autoloader" href="http://php.net/manual/en/language.oop5.autoload.php" target="_blank">here</a> it&#8217;s quite simple and can be expanded.</p>
<p>A basic autoloader is this:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$class_name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
<p>As is said this is pretty basic, but it gets the job done, but this will load all the classes from a single folder, what if you have lots of classes and have them all in different folders? Well we need to modify this function to cope with that. First though is the class names, normally you would do a class like this:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
<p>In order to have a class loaded from a folder we need to change that class name to include the folder we want it to be part of. So our original class becomes this:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Bases_MyClass
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
<p>Then we can modify our autoloader to load from folders:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$class_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #000088;">$class_name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
<p>This will now load Bases_MyClass from the file Bases/MyClass.php now that wasn&#8217;t so hard, just put an underscore every time you want to use another folder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syntaxerror.org.uk/php/autoloader-basics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

