<?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"
	>

<channel>
	<title>Crystal PHP</title>
	<atom:link href="http://www.crystalphp.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://crystalphp.com</link>
	<description>PHP For Designers</description>
	<pubDate>Wed, 30 Apr 2008 15:19:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Simple PHP Form Tutorial 1</title>
		<link>http://crystalphp.com/forms/simple-php-form-tutorial-1/</link>
		<comments>http://crystalphp.com/forms/simple-php-form-tutorial-1/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 19:38:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Forms]]></category>

		<category><![CDATA[form basics]]></category>

		<guid isPermaLink="false">http://crystalphp.com/forms/simple-php-form-tutorial-1/</guid>
		<description><![CDATA[Please Note: This form series assumes you are familiar with basic HTML, CSS and PHP. Basic PHP means you understand syntax such as &#60;?php, ?&#62;, echo, $variables, and include. 
I am going to start out with some simple php form examples and build on them. The end result will be a flexible php form that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Please Note: This form series assumes you are familiar with basic HTML, CSS and PHP. Basic PHP means you understand syntax such as &lt;?php, ?&gt;, echo, $variables, and include.</strong> </p>
<p>I am going to start out with some simple php form examples and build on them. The end result will be a flexible php form that you can easily put in any page and it will all controlled by arrays.<br />
The reason you want to have some type of array controller is that once you are used to it, it is much cleaner to create and edit your forms. It will eliminate all the tedious work and prevent errors.</p>
<p> That being said, below you will find a php form in its most basic state. I will point out some of the highlights.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;link rel=<span class="st0">&quot;stylesheet&quot;</span> type=<span class="st0">&quot;text/css&quot;</span> href=<span class="st0">&quot;style.css&quot;</span> /&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
<span class="kw2">&lt;?php</span></p>
<p>&nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8217;submitButton&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//Get the input from the form</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$name</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$email</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;email&quot;</span><span class="br0">&#93;</span>;&nbsp; <br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$comments</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;comments&quot;</span><span class="br0">&#93;</span>;&nbsp; <br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//Assemble the strings</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$fContent</span> = <span class="re0">$name</span> . <span class="st0">&#8216;|&#8217;</span> . <span class="re0">$email</span> . <span class="st0">&#8216;|&#8217;</span> . <span class="re0">$comments</span> . <span class="st0">&quot;<span class="es0">\r</span><span class="es0">\n</span>&quot;</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$pContent</span> = <span class="re0">$name</span> . <span class="st0">&#8216;&lt;br&gt;&#8217;</span> . <span class="re0">$email</span> . <span class="st0">&#8216;&lt;br&gt;&#8217;</span> . <span class="re0">$comments</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// In our example we&#8217;re opening $filename in append mode.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// The file pointer is at the bottom of the file hence</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// that&#8217;s where $cContent will go when we fwrite() it.</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$handle</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="st0">&#8216;form.txt&#8217;</span>,<span class="st0">&#8216;a&#8217;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//write to the file</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<a href="http://www.php.net/fwrite"><span class="kw3">fwrite</span></a><span class="br0">&#40;</span><span class="re0">$handle</span>,<span class="re0">$fContent</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//close the file</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$handle</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//Write message to browser</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;You Submitted:&lt;br&gt;&#8217;</span> . <span class="re0">$pContent</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">else</span><span class="br0">&#123;</span></p>
<p><span class="kw2">?&gt;</span></p>
<p>&nbsp; &nbsp;&lt;form action=<span class="st0">&quot;index.php&quot;</span> method=<span class="st0">&quot;post&quot;</span>&gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&lt;fieldset&gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&lt;legend&gt;My Form&lt;/legend&gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;label&gt;Name:&lt;/label&gt;&lt;input type=<span class="st0">&quot;text&quot;</span> name=<span class="st0">&quot;name&quot;</span> &gt;&lt;/p&gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;label&gt;Email:&lt;/label&gt;&lt;input type=<span class="st0">&quot;text&quot;</span> name=<span class="st0">&quot;email&quot;</span> &gt;&lt;/p&gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;label&gt;Comments:&lt;/label&gt;&lt;textarea name=<span class="st0">&quot;comments&quot;</span> &gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;/textarea&gt;&lt;/p&gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;p&gt;&lt;input type=<span class="st0">&quot;submit&quot;</span> value=<span class="st0">&quot;Go&quot;</span> name=<span class="st0">&quot;submitButton&quot;</span> <span class="kw2">class</span>=<span class="st0">&quot;submit&quot;</span>&gt;&lt;/p&gt;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&lt;/fieldset&gt;<br />
&nbsp; &nbsp;&lt;/form&gt;</p>
<p><span class="kw2">&lt;?php</span> <span class="br0">&#125;</span> <span class="kw2">?&gt;</span></p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</div>
<h2>The Form</h2>
<p>I will start at the bottom where the form displays as this is the default action.<br />
Here we are setting up the form</p>
<div class="dean_ch" style="white-space: wrap;">&lt;form action=<span class="st0">&quot;index.php&quot;</span> method=<span class="st0">&quot;post&quot;</span>&gt;</div>
<p>The call &#8220;action&#8221; refers to the page that the form will go to when the submit button is pressed. In our case, it is calling itself. The &#8220;method&#8221; refers to how the form will send the data. The two types are post and get. A form is usually sent &#8220;post&#8221; and a link is sent via &#8220;get&#8221;. It is possible to send a form via &#8220;get&#8221;, although if you do, all the values will show in the URL. </p>
<p>It is important to know which way you are sending the data, post vs. get, because at the top of the script we will be checking our PHP $_POST array for the form values.</p>
<p>The next thing to be aware of is the name you are giving your form fields as this will be the part of the $_POST array that we check for the values after we submit. In this case we will be looking for $_POST['email']</p>
<div class="dean_ch" style="white-space: wrap;">&lt;input type=<span class="st0">&quot;text&quot;</span> name=<span class="st0">&quot;email&quot;</span> &gt;</div>
<p>The last thing to note with our form is the submit button. I have named it &#8220;submitButton&#8221; and at the top of the script we will be checking for $_POST['submitButton'] to see if the form has been submitted. You can check for any form value when you are testing for a submitted form, but checking for the submit button is a clean way to go.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;input type=<span class="st0">&quot;submit&quot;</span> value=<span class="st0">&quot;Go&quot;</span> name=<span class="st0">&quot;submitButton&quot;</span> <span class="kw2">class</span>=<span class="st0">&quot;submit&quot;</span>&gt;</div>
<h2>The PHP</h2>
<p>We are now at the top of the script and will be checking to see if the form has been submitted.</p>
<p>This is the conditional statement that says if the form has been submitted, lets do some PHP, if not, lets display the form.<br />
<code>if(//some condition){ //process the form}. </code>Here we are using the php function isset() to test our $_POST array that holds all our form data. </p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8217;submitButton&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">//php code</span><br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="co1">//display the html form</span><br />
<span class="br0">&#125;</span></div>
<h4>The $_POST array</h4>
<p>Here is the $_POST array with its values it got from a submitted form. You can see how the name fields from the actual form elements correspond to the &#8220;key&#8221; elements of the array. ( [key] => [value] ) with the value being the data that was entered in the form.<br />
<code>Array<br />
(<br />
    [name] => Matt<br />
    [email] => mk@mattkern.com<br />
    [comments] => Wow, this is groovy.<br />
    [submitButton] => Go<br />
)</code></p>
<p>Now that you know what an array looks like, it is easier to visualize the isset($_POST['submitButton']) test.</p>
<h4>Assigning Variables and formatting</h4>
<p>Next we are taking each form element from the $_POST array and assiging its value to a variable for later use.</p>
<div class="dean_ch" style="white-space: wrap;">&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//Get the input from the form</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$name</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$email</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;email&quot;</span><span class="br0">&#93;</span>;&nbsp; <br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$comments</span> = <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&quot;comments&quot;</span><span class="br0">&#93;</span>;&nbsp;</div>
<p>Now we are just assembling our new data into a format that is useful for us. The first variable $fContent I am going to write to a file, thats why it uses the text new line characters &#8220;\r\n&#8221;. $pContent is going to print to the screen so I am assembling it with HTML. </p>
<p>The period &#8220;.&#8221; in php, when used with strings, simply joins the strings together.</p>
<div class="dean_ch" style="white-space: wrap;">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//Assemble the strings</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$fContent</span> = <span class="re0">$name</span> . <span class="st0">&#8216;|&#8217;</span> . <span class="re0">$email</span> . <span class="st0">&#8216;|&#8217;</span> . <span class="re0">$comments</span> . <span class="st0">&quot;<span class="es0">\r</span><span class="es0">\n</span>&quot;</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$pContent</span> = <span class="re0">$name</span> . <span class="st0">&#8216;&lt;br&gt;&#8217;</span> . <span class="re0">$email</span> . <span class="st0">&#8216;&lt;br&gt;&#8217;</span> . <span class="re0">$comments</span>;</div>
<h4>Output</h4>
<p>Our final step is to take our formatted data and output it. The first 3 lines writes our text formatted variable to a text file and the final line prints our browser formatted variable to the screen.</p>
<div class="dean_ch" style="white-space: wrap;">&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//write to the file</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="re0">$handle</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="st0">&#8216;form.txt&#8217;</span>,<span class="st0">&#8216;a&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<a href="http://www.php.net/fwrite"><span class="kw3">fwrite</span></a><span class="br0">&#40;</span><span class="re0">$handle</span>,<span class="re0">$fContent</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$handle</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="co1">//Write message to browser</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;You Submitted:&lt;br&gt;&#8217;</span> . <span class="re0">$pContent</span>;</div>
<p>And that is that!</p>
<p>Obviously this is a very basic form with a lot of things to expand on, but it all works and hopefully the whole php form processing process makes a little more sense to you now.</p>
<p>Our next lesson is going to get into error checking so stay tuned.</p>
<p>Please free to leave me a comment if you found this tutorial helpful or if you have some questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/forms/simple-php-form-tutorial-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>include and require</title>
		<link>http://crystalphp.com/basics/include-and-require/</link>
		<comments>http://crystalphp.com/basics/include-and-require/#comments</comments>
		<pubDate>Sat, 22 Mar 2008 15:05:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[The Basics]]></category>

		<category><![CDATA[functions]]></category>

		<guid isPermaLink="false">http://crystalphp.com/?p=10</guid>
		<description><![CDATA[These two functions will save you a lot of time.
They are basically identical except the way they handle errors.
What&#8217;s It For?
Lets say you have a five page website. On those five pages everything is identical except for the content area. What most people do in this case is to take the common parts, save them [...]]]></description>
			<content:encoded><![CDATA[<p>These two functions will save you a lot of time.</p>
<p>They are basically identical except the way they handle errors.</p>
<h2>What&#8217;s It For?</h2>
<p>Lets say you have a five page website. On those five pages everything is identical except for the content area. What most people do in this case is to take the common parts, save them off in their own file and include them in the content file.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;head&gt;<br />
// all the html head information<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id=&quot;content&quot;&gt;<br />
//unique content goes here<br />
&lt;/div&gt;<br />
&lt;div id=&quot;sidebar_menu&quot;&gt;<br />
//menus<br />
&lt;/div&gt;<br />
&lt;div id=&quot;footer&quot;&gt;&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div>
<p>Identify the elements that repeat in every page. In this case it is the header, sidebar and footer.<br />
I am going to make one file for the header, one for the content, and one for the sidebar and footer.</p>
<p>Here is what the header and footer will look like.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;!&#8211; <a href="http://www.php.net/header"><span class="kw3">header</span></a>.php &#8211;&gt;<br />
&lt;head&gt;<br />
<span class="co1">// all the html head information</span><br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id=<span class="st0">&quot;content&quot;</span>&gt;<br />
&nbsp;</div>
<p></p>
<div class="dean_ch" style="white-space: wrap;">
&lt;!&#8211; footer.php &#8211;&gt;</p>
<p>&lt;!&#8211; off content div &#8211;&gt;<br />
&lt;/div&gt;<br />
&lt;div id=<span class="st0">&quot;sidebar_menu&quot;</span>&gt;<br />
<span class="co1">//menus</span><br />
&lt;/div&gt;<br />
&lt;div id=<span class="st0">&quot;footer&quot;</span>&gt;&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</div>
<p>
Now each content page you have will look something like this:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?</span> <span class="kw1">include</span><span class="br0">&#40;</span><span class="st0">&#8216;header.php&#8217;</span><span class="br0">&#41;</span>; <span class="kw2">?&gt;</span><br />
<span class="co1">// unique content here</span><br />
<span class="kw2">&lt;?</span> <span class="kw1">include</span><span class="br0">&#40;</span><span class="st0">&#8216;footer.php&#8217;</span><span class="br0">&#41;</span>; <span class="kw2">?&gt;</span></div>
<p>if you are using require, it looks almost identical:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?</span> <span class="kw1">require</span><span class="br0">&#40;</span><span class="st0">&#8216;header.php&#8217;</span><span class="br0">&#41;</span>; <span class="kw2">?&gt;</span><br />
<span class="co1">// unique content here</span><br />
<span class="kw2">&lt;?</span> <span class="kw1">require</span><span class="br0">&#40;</span><span class="st0">&#8216;footer.php&#8217;</span><span class="br0">&#41;</span>; <span class="kw2">?&gt;</span></div>
<p>The difference between the two is if the page you are trying to include/require cannot be found, include will return a warning but the program will continue, but require returns a fatal error and execution of the page stops. Which one you use depends on how Draconian you want to be in case of a file not found error.</p>
<p>With using this type of approach across all your pages, when you have to make changes to the common files, you are just changing it in one spot and not in multiple files.</p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/basics/include-and-require/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Intro To PHP Arrays</title>
		<link>http://crystalphp.com/uncategorized/intro-to-php-arrays/</link>
		<comments>http://crystalphp.com/uncategorized/intro-to-php-arrays/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 14:40:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://crystalphp.com/?p=9</guid>
		<description><![CDATA[An array is just a grouping of similar items. There are 2 kinds of arrays.
The First Kind
The first type is referenced by numbers. This is what an array with 4 items looks like.
Array
(
    [0] => eggs
    [1] => milk
    [2] => bread
    [3] [...]]]></description>
			<content:encoded><![CDATA[<p>An array is just a grouping of similar items. There are 2 kinds of arrays.</p>
<h4>The First Kind</h4>
<p>The first type is referenced by numbers. This is what an array with 4 items looks like.</p>
<p><code>Array<br />
(<br />
    [0] => eggs<br />
    [1] => milk<br />
    [2] => bread<br />
    [3] => butter<br />
)</code></p>
<p>To define this array in PHP, we would write:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <span class="re0">$shopping</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;eggs&#8217;</span>,<span class="st0">&#8216;milk&#8217;</span>,<span class="st0">&#8216;bread&#8217;</span>,<span class="st0">&#8216;butter&#8217;</span><span class="br0">&#41;</span>;?&gt;</div>
<p>Notice how we did not have to actually write the numbers 0 thru 4. They are implied with this type of array.</p>
<p>To print out the word &#8220;eggs&#8221; we would type:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$shopping</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="kw2">?&gt;</span></div>
<p>The zero refers to the array entry. To print out butter we would type:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$shopping</span><span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span> <span class="kw2">?&gt;</span></div>
<h4>The Second Kind</h4>
<p>The second type of array is an associative array. It looks like this:<br />
<code>Array<br />
(<br />
    [monday] => eggs<br />
    [tuesday] => milk<br />
    [wednesday] => bread<br />
    [thursday] => butter<br />
)</code></p>
<p>To define this in PHP we would type:</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw2">&lt;?php</span> <span class="re0">$breakfast</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;monday&#8217;</span> =&gt; <span class="st0">&#8216;eggs&#8217;</span>,<span class="st0">&#8216;tuesday&#8217;</span> =&gt; <span class="st0">&#8216;milk&#8217;</span>,<span class="st0">&#8216;wednesday&#8217;</span> =&gt; <span class="st0">&#8216;bread&#8217;</span>,<span class="st0">&#8216;thursday&#8217;</span> =&gt; <span class="st0">&#8216;butter&#8217;</span><span class="br0">&#41;</span>;?&gt;</div>
<p>To print out Monday&#8217;s breakfast, we would type:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$breakfast</span><span class="br0">&#91;</span><span class="st0">&#8216;monday&#8217;</span><span class="br0">&#93;</span>;?&gt;</div>
<p>Arrays are very powerful and there are many ways to access, print and manipulate arrays in PHP. We haven&#8217;t gone into too much detail here, but hopefully this makes you more comfortable of what an array is as we get further into the tutorials.</p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/uncategorized/intro-to-php-arrays/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Variables</title>
		<link>http://crystalphp.com/basics/variables/</link>
		<comments>http://crystalphp.com/basics/variables/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 03:05:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[The Basics]]></category>

		<category><![CDATA[basic]]></category>

		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://crystalphp.com/?p=3</guid>
		<description><![CDATA[What Are They?
A variable is just a container that is meant to hold something for use later on. Just like a little carrying case. 
There are a many different types of variables but the ones you will be using most will be strings or numbers. When I say &#8220;strings&#8221;, all that means is a series [...]]]></description>
			<content:encoded><![CDATA[<h2>What Are They?</h2>
<p>A variable is just a container that is meant to hold something for use later on. Just like a little carrying case. </p>
<p>There are a many different types of variables but the ones you will be using most will be strings or numbers. When I say &#8220;strings&#8221;, all that means is a series of letters or other characters, i.e. ?,&#038;,@ etc&#8230; </p>
<p>In PHP, a variable is written by using a dollar sign and you assign a value to it with an equals sign. </p>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$myVariable</span> = <span class="st0">&#8216;I Love Home Cookin&#8217;</span>;</div>
<p>There are 5 parts to this line of code.</p>
<ol>
<li>The Variable: $myVariable - This is the actual variable. It is our handy carrying case that now contains the words &#8220;I Love Home Cookin&#8221; (without the quotes).</li>
<li> Equals Sign: The equals sign assigns the words &#8220;I Love Home Cookin&#8221; to the variable $myVariable.</li>
<li>Single Quotes: The words &#8220;I Love Home Cookin&#8221; are surrounded by single quotes. There are specific times when you want to use single quotes, double quotes or no quotes. For now, if you are assigning any word or characters to your variable, use single quotes.</li>
<li>The String: &#8220;I Love Home Cookin&#8221;. </li>
<li>The Semicolon: First used in <a href="http://en.wikipedia.org/wiki/Semicolon">England</a> in 1591, this proud little character marks the end of a line of code in PHP.</li>
</ol>
<p>To assign a number to a variable it is almost the same syntax but without the quotes.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$myVariable</span> = <span class="nu0">42</span>;</div>
<h2>When Do I Use It</h2>
<p>Here is a simple rule of thumb if you are just starting out with PHP. </p>
<blockquote><p>&#8220;If you ever have to type anything more than one time, use a variable. &#8220;</p></blockquote>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$myWebsite</span> = <span class="st0">&#8216;&lt;a href=&quot;http://mattkern.com&quot;&gt;MattKern.com&lt;/a&gt;&#8217;</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;Come visit my website at &#8216;</span> . <span class="re0">$myWebsite</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;br&gt;There are lots of informative posts to read&#8217;</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;br&gt;Did I mention you should go here? &#8216;</span> . <span class="re0">$myWebsite</span>;</div>
<p>Of course this prints:<br />
Come visit my website at <a href="http://mattkern.com">MattKern.com</a><br />
There are lots of informative posts to read<br />
Did I mention you should go here? <a href="http://mattkern.com">MattKern.com</a></p>
<p>Programming is all about saving time and avoiding repetition. That is a variables main goal in life.</p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/basics/variables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>echo versus print</title>
		<link>http://crystalphp.com/basics/echo-versus-print/</link>
		<comments>http://crystalphp.com/basics/echo-versus-print/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 04:04:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[The Basics]]></category>

		<category><![CDATA[echo]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[print]]></category>

		<guid isPermaLink="false">http://crystalphp.com/uncategorized/echo-versus-print/</guid>
		<description><![CDATA[OK, so you actually wanted to write something to the screen. This is where echo and print come in handy. 
echo &#8216;Welcome to the Social&#8217;;
This prints your favorite Zune tag:
Welcome to the Social
Print literally is the same call. 
print &#8216;Welcome to the Social&#8217;;
Echo is more commonly used but I do use print when I am [...]]]></description>
			<content:encoded><![CDATA[<p>OK, so you actually wanted to write something to the screen. This is where echo and print come in handy. </p>
<div class="dean_ch" style="white-space: wrap;"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;Welcome to the Social&#8217;</span>;</div>
<p>This prints your favorite Zune tag:<br />
Welcome to the Social</p>
<p>Print literally is the same call. </p>
<div class="dean_ch" style="white-space: wrap;"><a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;Welcome to the Social&#8217;</span>;</div>
<p>Echo is more commonly used but I do use print when I am writing and testing web pages. I will output the actual web page code using echo but use print to output debug statements.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$testVar</span> = <span class="nu0">10</span>;<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;The testvar should equal 10&#8242;</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$testVar</span>;</div>
<p>For such a small example it seems pointless but it can come in handy when your web site grows to 20 plus pages with many include files and suddenly your debug message &#8216;I Am Here&#8217; is popping out of your header. Simply search for the &#8220;print&#8221; tag and you will be able to identify your debug print statements easily.</p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/basics/echo-versus-print/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Defining a new PHP page</title>
		<link>http://crystalphp.com/basics/defining-a-new-php-page/</link>
		<comments>http://crystalphp.com/basics/defining-a-new-php-page/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 02:36:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[The Basics]]></category>

		<guid isPermaLink="false">http://crystalphp.com/?p=8</guid>
		<description><![CDATA[As you did in the previous example, we are going to define a new php page.
Open your text editor and make a new file. Go to your localhost root folder and make a new folder called &#8220;test&#8221;. Inside of &#8220;test&#8221; save your new file as index.php.
In index.php type or copy this:
&#60;?php
echo &#34;This is a new [...]]]></description>
			<content:encoded><![CDATA[<p>As you did in the previous example, we are going to define a new php page.</p>
<p>Open your text editor and make a new file. Go to your localhost root folder and make a new folder called &#8220;test&#8221;. Inside of &#8220;test&#8221; save your new file as index.php.</p>
<p>In index.php type or copy this:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;This is a new PHP page.&quot;</span>;<br />
<span class="kw2">?&gt;</span><br />
This is just Raw HTML from inside a PHP page.<br />
<span class="kw2">&lt;?php</span><br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;Back to the PHP.&#8217;</span>;<br />
<span class="kw2">?&gt;</span></div>
<p>To test your new creation go to http://localhost/test/</p>
<p>As you can see, you need the opening ( &lt;?php ) and closing ( ?&gt; ) php tags before you can actually write any php code. After the closing PHP tag you are able to write straight HTML.</p>
<p>You can go in and out of the PHP tags as many times on a page as you want until you are cross eyed.</p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/basics/defining-a-new-php-page/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Testing Your PHP Installation</title>
		<link>http://crystalphp.com/basics/testing-your-php-installation/</link>
		<comments>http://crystalphp.com/basics/testing-your-php-installation/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 02:20:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[The Basics]]></category>

		<category><![CDATA[phpinfo]]></category>

		<guid isPermaLink="false">http://crystalphp.com/?p=7</guid>
		<description><![CDATA[After you have installed PHP, you need to test the installation.
This is a very simple one liner. Using your text editor, make a new file called phpinfo.php and paste this inside. 
&#60;?php phpinfo&#40;&#41; ?&#62;
Save this file in your root web directory for whatever PHP installer you used. 
Now go to http://localhost/phpinfo.php
If you have successfully installed [...]]]></description>
			<content:encoded><![CDATA[<p>After you have installed PHP, you need to test the installation.</p>
<p>This is a very simple one liner. Using your text editor, make a new file called phpinfo.php and paste this inside. </p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <a href="http://www.php.net/phpinfo"><span class="kw3">phpinfo</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">?&gt;</span></div>
<p>Save this file in your root web directory for whatever PHP installer you used. </p>
<p>Now go to http://localhost/phpinfo.php</p>
<p>If you have successfully installed PHP you will see a screen full of all your php settings.</p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/basics/testing-your-php-installation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installing PHP</title>
		<link>http://crystalphp.com/basics/installing-php/</link>
		<comments>http://crystalphp.com/basics/installing-php/#comments</comments>
		<pubDate>Thu, 03 Jan 2008 01:55:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[The Basics]]></category>

		<category><![CDATA[install]]></category>

		<guid isPermaLink="false">http://crystalphp.com/?p=6</guid>
		<description><![CDATA[To start with PHP you will need to install it on your local machine. Luckily, this is easy.
There are 2 great point and click products that will do this for you. They both work quite well. I prefer WAMP over XXAMP but for pretty subtle reasons. Either one will get the job done for you. [...]]]></description>
			<content:encoded><![CDATA[<p>To start with PHP you will need to install it on your local machine. Luckily, this is easy.</p>
<p>There are 2 great point and click products that will do this for you. They both work quite well. I prefer WAMP over XXAMP but for pretty subtle reasons. Either one will get the job done for you. </p>
<p>Just download the install file for your OS and follow the directions.</p>
<p><a href="http://www.en.wampserver.com/">WAMP</a><br />
<a href="http://www.apachefriends.org/en/xampp.html">XXAMP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crystalphp.com/basics/installing-php/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
