<?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>Marion Dorsett&#039;s FigmentThinking.com &#187; PHP</title>
	<atom:link href="http://www.figmentthinking.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.figmentthinking.com</link>
	<description>Learn how to write better code. Simple techniques to produce faster results and save you time.</description>
	<lastBuildDate>Thu, 28 Jul 2011 12:40:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Process Your PHP Form POSTs Faster.</title>
		<link>http://www.figmentthinking.com/2008/04/23/process-your-php-form-posts-faster/</link>
		<comments>http://www.figmentthinking.com/2008/04/23/process-your-php-form-posts-faster/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 03:33:39 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/?p=43</guid>
		<description><![CDATA[<br/>The Scenario: You setup a contact form for people to send you email.  When the form is submitted, you want to assign each of the POST, GET or REQUEST values to a variable with the same name as the key. (You could do this for a number of reasons, but that&#8217;s a different topic.) The [...]]]></description>
			<content:encoded><![CDATA[<br/><p><strong>The Scenario:</strong></p>
<p>You setup a contact form for people to send you email.  When the form is submitted, you want to assign each of the POST, GET or REQUEST values to a variable with the same name as the key. (You could do this for a number of reasons, but that&#8217;s a different topic.)</p>
<p><strong>The Problem:</strong></p>
<p>Ugh! Doing this can be really time consuming, especially if you have a really long form.  Presonally, I would just use the array element vs. setting creating a new variable, but if you must, I suggest using a foreach() loop to create the variables for you.</p>
<p><strong>The Solution:</strong><span id="more-43"></span><br />
Sample form:</p>

<div class="wp_codebox"><table><tr id="p433"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p43code3"><pre class="html" style="font-family:monospace;">&lt;form&gt;Email:
&lt;input name=&quot;email&quot; type=&quot;text&quot; /&gt;
&lt;input type=&quot;submit&quot; /&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>When the form is submitted, use a loop and a variable variable to do the job for you.</p>

<div class="wp_codebox"><table><tr id="p434"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p43code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// create variable name from key  </span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
        Assuming `email` was the key, the above would
        create a new variable called $email
        */</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end foreach</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end if</span>
<span style="color: #666666; font-style: italic;"># Process your code here calling each new var
</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2008/04/23/process-your-php-form-posts-faster/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Script.aculo.us and TinyMCE Incompatibility Solution</title>
		<link>http://www.figmentthinking.com/2007/06/21/scriptaclous-and-tinymce-incompatibility-solution/</link>
		<comments>http://www.figmentthinking.com/2007/06/21/scriptaclous-and-tinymce-incompatibility-solution/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 16:12:52 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/scriptaclous-and-tinymce-incompatibility-solution/</guid>
		<description><![CDATA[<br/>I found that when I tried to use Script.aculo.us and TinyMCE together, that I lost 1 functionality of one of the two scripts on Firefox. The solution I found was to place the Script.aculo.us &#60;script&#62; tags directly below the &#60;body&#62; tag. 1 2 3 4 5 6 7 ... &#60;script type=&#34;text/javascript&#34;&#62;&#60;!--mce:0--&#62;&#60;/script&#62; &#60;script type=&#34;text/javascript&#34;&#62;&#60;!--mce:1--&#62;&#60;/script&#62; &#160; &#60;script [...]]]></description>
			<content:encoded><![CDATA[<br/><p>I found that when I tried to use Script.aculo.us and TinyMCE together, that I lost 1 functionality of one of the two scripts on Firefox.  The solution I found was <span id="more-39"></span>to place the Script.aculo.us &lt;script&gt; tags directly below the &lt;body&gt; tag.</p>
<div>

<div class="wp_codebox"><table><tr id="p396"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p39code6"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;scripts/prototype.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">2</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;scripts/scriptaculous.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">3</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
...</pre></td></tr></table></div>

</div>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/06/21/scriptaclous-and-tinymce-incompatibility-solution/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Working With A PHP Configuration File</title>
		<link>http://www.figmentthinking.com/2007/03/18/working-with-a-php-configuration-file/</link>
		<comments>http://www.figmentthinking.com/2007/03/18/working-with-a-php-configuration-file/#comments</comments>
		<pubDate>Mon, 19 Mar 2007 04:36:17 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/working-with-a-php-configuration-file/</guid>
		<description><![CDATA[<br/>TRUE or FALSE: &#8220;It&#8217;s easier to update one file or 10 files.&#8221; This statement is True. The concept of a configuration file is that it stores data in one location that any other file on the web site can access. The data that is stored in a configuration file can be unlimited, but usually contains [...]]]></description>
			<content:encoded><![CDATA[<br/><p>TRUE or FALSE: &#8220;It&#8217;s easier to update one file or 10 files.&#8221;  This statement is True.</p>
<p>The concept of a configuration file is that it stores data in one location that any other file on the web site can access.  The data that is stored in a configuration file can be unlimited, but usually contains data such as by not limited to the following:</p>
<ul>
<li>MySQL Database, Username and Password</li>
<li>Document Root Folder</li>
<li>To use Cookies or Sessions</li>
<li>Set time limit for Sessions</li>
<li>Custom variables for web applications</li>
<li>and etc.</li>
</ul>
<p><span id="more-35"></span>Too many times I&#8217;ve assumed responsibility for a web site where the previous developer didn&#8217;t make use of a PHP configuration file.  Often the most common things I find is that the MySQL information is on every single page, and in the even that we have to change the password, I have to either setup a config file, or change every file that&#8217;s using that information.</p>
<p>I opt for changing each page to use the configuration file and set the MySQL information in just one location.  This makes my work a lot easier in the future.  I can now set other information in this config file as well based on the site and it&#8217;s purpose.</p>
<p>The problem with having to change the same data in multiple files takes additional time and presents a larger margin for human error, where with a config file change can be made once, and human error can be corrected much quicker and easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/03/18/working-with-a-php-configuration-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use As Many PHP Files As You Need</title>
		<link>http://www.figmentthinking.com/2007/03/12/use-as-many-php-files-as-you-need/</link>
		<comments>http://www.figmentthinking.com/2007/03/12/use-as-many-php-files-as-you-need/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 00:52:01 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/use-as-many-php-files-as-you-need/</guid>
		<description><![CDATA[<br/>I&#8217;m working with a friend &#8211; helping him with some dynamic coding &#8211; on a web site. The web site was put together by a different webmaster and it functions. The clients needs have changed over time, and changes are need to the site to comply with a few legal things (it deals with housing.) [...]]]></description>
			<content:encoded><![CDATA[<br/><p>I&#8217;m working with a friend &#8211; helping him with some dynamic coding &#8211; on a web site. The web site was put together by a different webmaster and it functions. The clients needs have changed over time, and changes are need to the site to comply with a few legal things (it deals with housing.) As I begin looking at the PHP code, I can tell the person who programmed it was very intelligent, but fell prey to some of the things that irritate me, and create problems when trying to update the code as I&#8217;m doing now.</p>
<p>First, <a target="_blank" href="http://www.figmentthinking.com/commenting-your-php-code/">they didn&#8217;t comment any of their PHP code</a>, second <a target="_blank" href="http://www.figmentthinking.com/looping-through-arrays/">they did make use of arrays</a>, but did a poor job of it, and they posted all of the forms back to themselves, which brings me to the point of this post. Use more than one file if you have to, and don&#8217;t be afraid to do so. Here&#8217;s the problem with posting a form back to itself.</p>
<p><span id="more-31"></span>In this case we have a form that is sending the accumulated form data via email to the client for review. That data is also saved to a database so that it can be edited and tracked in the event that the user becomes a tenant. The problem is that since the form post to itself, the client receives and email, and the database gets a new row added every time the page is refreshed after the user fills it out.</p>
<p>When I saw this I recommended to my friend that over time we fix this. It turns out that there are revisions that need to be made to the form anyway, so as we fix the form, we&#8217;ll setup additional pages to process the form data, and redirect to the next part of the form ( there are 3 parts to the form.) This way when the user clicks the final submit button, the information will be emailed, collected in to the database and then the user will be taken to a thank you page. This process will keep the redundant &amp; superfluous rows out of the clients inbox and database.</p>
<p>In this example, just by processing the form data with another, you reduce the irritation to the client and to yourself because they won&#8217;t keep asking&#8230; &#8220;Why do I get two or three emails for some people, and why do they show up that many times in the database?&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/03/12/use-as-many-php-files-as-you-need/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Commenting Your PHP Code</title>
		<link>http://www.figmentthinking.com/2007/03/12/commenting-your-php-code/</link>
		<comments>http://www.figmentthinking.com/2007/03/12/commenting-your-php-code/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 00:21:41 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/commenting-your-php-code/</guid>
		<description><![CDATA[<br/>About two years ago I started working for a local web firm. It was small, at that time there we&#8217;re only 3 of us, and I was the only PHP developer on staff. We had one client who used our services, combined with another web vendor. Normally we just spit out regular static HTML pages [...]]]></description>
			<content:encoded><![CDATA[<br/><p>About two years ago I started working for a local web firm. It was small, at that time there we&#8217;re only 3 of us, and I was the only PHP developer on staff. We had one client who used our services, combined with another web vendor. Normally we just spit out regular static HTML pages for them, until one day something happened, and we were passed a job that required editing some PHP code from the other vendor.</p>
<p>I honestly don&#8217;t remember who the client was, or what the PHP that I was editing was used for, all I remember is that it was the worst code I had ever come into contact with. Nothing made sense, the coding method was random, nothing was optimized, and I wanted to re-write the whole thing and start over. Time did not permit a total re-write, so I was stuck editing the nasty code that was before me. So as I made my edits, I started commenting the code, it went something like this&#8230;</p>
<p><span id="more-28"></span></p>

<div class="wp_codebox"><table><tr id="p288"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p28code8"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># I don't know what these moron's where thinking here, but it should work like this...
</span><span style="color: #009900;">&#123;</span>some php code<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;"># Were they smoking crack when they tried to set this up?
</span><span style="color: #009900;">&#123;</span>some php code<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I fixed the PHP coding problems, uploaded the files and everything worked as the client requested. I thought nothing else about the project until my boss was on the phone with the other web vendor, trying to explain how I had fixed their code.</p>
<p>What I realized was that my boss was on the phone with the `morons` &#8211; as I had called them in my PHP comments &#8211; who wrote the horrible PHP code that frustrated me. My boss got off the phone and I asked him&#8230; so how mad were they? He didn&#8217;t know what I meant. I confessed to my having adding some rude comments in the code as I fixed it. He laughed, and said they never said a word about it.</p>
<p>The moral to this story is that if you comment your code, whether your a moron, or really smoking crack when you write it, chances are someone will better understand what you were thinking when you wrote it and have an easier time maintaining your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/03/12/commenting-your-php-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looping Through Arrays</title>
		<link>http://www.figmentthinking.com/2007/03/08/looping-through-arrays/</link>
		<comments>http://www.figmentthinking.com/2007/03/08/looping-through-arrays/#comments</comments>
		<pubDate>Thu, 08 Mar 2007 05:58:30 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/looping-through-arrays/</guid>
		<description><![CDATA[<br/>One of my favorite time saving techniques is to loop through an array whether it&#8217;s an indexed or an associative array, I&#8217;ve saved more time on projects by looping through arrays vs. writing code to handle each value of the array. I bring this up because I&#8217;ve had to update too many PHP scripts written [...]]]></description>
			<content:encoded><![CDATA[<br/><p>One of my favorite time saving techniques is to loop through an array whether it&#8217;s an indexed or an associative array, I&#8217;ve saved more time on projects by looping through arrays vs. writing code to handle each value of the array. I bring this up because I&#8217;ve had to update too many PHP scripts written by other developers where they handle each and every value of the $_POST or $_GET arrays as individual values to be parsed.</p>
<p>Here&#8217;s a practical example.<span id="more-29"></span> It&#8217;s a good practice to remove any extra spaces from the beginning and ending of your POST values, especially before inserting that data into a database. Imagine a typical form asking for first name, last name, address (lines 1 and 2), city, state, zip and two phone numbers. I&#8217;ve seen code that has handled each one in an individual manner, but a loop can make short work of it.</p>
<p>Loop Example:</p>

<div class="wp_codebox"><table><tr id="p2911"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p29code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;"># look for POST array
</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># Loop through POST array
</span>    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
       <span style="color: #666666; font-style: italic;"># Remove whitespace and stripslashes.
</span>       <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end foreach</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end if</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The individual approach would be much longer and would require editing anytime the the form was modified. Looping through the array makes it fast and uses less code making it easier to maintain, reduces the file size and much cleaner code.</p>
<p>As of this post, I&#8217;m currently involved in a project where there is a 3 part form, easily 30 questions or more, and each form element is handled individually. Ugh! The original developer had way too much time on their hand and didn&#8217;t make use of any looping constructs.</p>
<p>This methodology works for both indexed and associative arrays. <em>Indexed arrays have numerical keys, whereas, associative arrays do not.</em></p>

<div class="wp_codebox"><table><tr id="p2912"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p29code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;"># Indexed Array
</span><span style="color: #000088;">$indexed</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$indexed</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$indexed</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Associative Array
</span><span style="color: #000088;">$associative</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$associative</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'two'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$associative</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'purple'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Generally, I&#8217;m having to save form data into a database, and it&#8217;s really nice to be able to clean up the POST data with a loop, and at the same time include code that will build the MySQL query command on the fly. If you can, I suggest giving loops a try, especially when it comes to processing array information.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/03/08/looping-through-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>There&#8217;s Always A Better Way</title>
		<link>http://www.figmentthinking.com/2007/03/07/theres-always-a-better-way/</link>
		<comments>http://www.figmentthinking.com/2007/03/07/theres-always-a-better-way/#comments</comments>
		<pubDate>Thu, 08 Mar 2007 03:49:48 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/theres-always-a-better-way/</guid>
		<description><![CDATA[<br/>I&#8217;m a firm believer in the statement, &#8220;There&#8217;s always a better way.&#8221; When I started learning PHP, I assumed that what I was reading was hardcore `gospel` truth. What I realized later as I was trying to maintain my code was, there is a better way to do this. I was really irritated when my [...]]]></description>
			<content:encoded><![CDATA[<br/><p>I&#8217;m a firm believer in the statement, &#8220;There&#8217;s always a better way.&#8221; When I started learning PHP, I assumed that what I was reading was hardcore `gospel` truth. What I realized later as I was trying to maintain my code was, there is a better way to do this. I was really irritated when my epiphany hit me. Irritated that I didn&#8217;t think of it sooner, but I was the novice and I chalked it up to learning, then I got really irritated at the authors of the PHP information I was reading because they never provided a clue, &#8220;there&#8217;s an easier way to do this&#8230;&#8221;</p>
<p><span id="more-27"></span>My epiphany was that I could create a configuration file and store my global variables that I needed to call over the whole site in one place. Not a hard concept to conceive, yet my focus was on learning PHP, and the authors of the books and tutorials I was reading were focused on providing that information in the smallest bits available.</p>
<p>The thing I&#8217;ve learned though is that I&#8217;m not the average programmer, and I don&#8217;t consider my self a programmer. I consider my self a web developer. What I build are web site applications and I develop the process by which an end user can control all or a portion of their web site based on their needs.</p>
<p>I don&#8217;t stick to conventional programming schema, instead I program the best, quickest and simplest solution I can think of at the time. Over time I have developed a solid core of modular files that I have been using for years now use as the base to my web applications. I&#8217;ve been working with PHP now since 2001 and I&#8217;m still finding better ways to work with my core files.</p>
<p>What will make you successful, is never settle for what your told. Accept it as a piece of the puzzle. Find out where it fits, and the as you learn more and more about PHP, find out how to shape it to fit better.</p>
<p>Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/03/07/theres-always-a-better-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>For PHP Beginners</title>
		<link>http://www.figmentthinking.com/2007/02/28/for-php-beginners/</link>
		<comments>http://www.figmentthinking.com/2007/02/28/for-php-beginners/#comments</comments>
		<pubDate>Wed, 28 Feb 2007 05:19:50 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/2007/02/28/for-php-beginners/</guid>
		<description><![CDATA[<br/>When I was first learning how to use PHP, I was looking for all the knowledge I could get. I bought book, read tutorials online, what ever I could find, people to talk to. I quickly realized that no two people had the same approach to teaching beginners and, they often made reference to not [...]]]></description>
			<content:encoded><![CDATA[<br/><p>When I was first learning how to use PHP, I was looking for all the knowledge I could get. I bought book, read tutorials online, what ever I could find, people to talk to. I quickly realized that no two people had the same approach to teaching beginners and, they often made reference to not providing information that they thought to be useful but possibly confusing.</p>
<p>WHAT! Are you kidding me? So while the author spouts off about how this function operates just like it&#8217;s C counter part <em>(which I know nothing about)</em>, they won&#8217;t provide me with knowledge that may be useful to the language I&#8217;m actually learning?</p>
<p>So if you&#8217;re just starting to learning PHP keep these helpful tips in mind.</p>
<p><span id="more-25"></span></p>
<ul>
<li><a target="_blank" href="http://www.figmentthinking.com/theres-always-a-better-way/">Always assume there&#8217;s a smarter way to do something in PHP than how it&#8217;s presented to you.</a></li>
<li><a target="_blank" href="http://www.figmentthinking.com/commenting-your-php-code/">If you start commenting your PHP code now you&#8217;ll continue to do it in the future. Commenting your PHP code now will help you and those who may have to maintain your PHP code after you&#8217;ve moved on.</a></li>
<li><a target="_blank" href="http://www.figmentthinking.com/looping-through-arrays/">Indexed and associative arrays can be looped using PHP which can save you a lot of time.</a></li>
<li><a target="_blank" href="http://www.figmentthinking.com/use-as-many-php-files-as-you-need/">Don&#8217;t be afraid to use as many PHP files as you need to keep your code separated and clean.</a></li>
<li><a target="_blank" href="http://www.figmentthinking.com/working-with-a-php-configuration-file/">Use a PHP configuration file to store common information that will affect the entire site. This way you can make a change in one location and the site will be updated. (Hint: MySQL connection information)</a></li>
</ul>
<p>What I&#8217;m not providing you with in this post are lengthy examples of each of the topics I&#8217;ve listed above. Whereas I don&#8217;t think the information will confuse you, more so that each bullet point is a lengthy topic with in itself. I&#8217;ll cover these topics in later posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/02/28/for-php-beginners/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Different Approach to Parsing HTML as PHP</title>
		<link>http://www.figmentthinking.com/2007/02/27/a-different-approach-to-parsing-html-as-php/</link>
		<comments>http://www.figmentthinking.com/2007/02/27/a-different-approach-to-parsing-html-as-php/#comments</comments>
		<pubDate>Wed, 28 Feb 2007 04:18:59 +0000</pubDate>
		<dc:creator>marion</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.figmentthinking.com/2007/02/27/a-different-approach-to-parsing-html-as-php/</guid>
		<description><![CDATA[<br/>On occasion it&#8217;s necessary for me to process HTML files as PHP. Reasons vary, but usually it&#8217;s because the clients web site was originally set up as static HTML and we need to process dynamic content, but due to SEO reasons, we can&#8217;t change the file extensions. Generally a simple .htaccess file can handle this [...]]]></description>
			<content:encoded><![CDATA[<br/><p>On occasion it&#8217;s necessary for me to process HTML files as PHP. Reasons vary, but usually it&#8217;s because the clients web site was originally set up as static HTML and we need to process dynamic content, but due to SEO reasons, we can&#8217;t change the file extensions.</p>
<p>Generally a simple .htaccess file can handle this process for you and make simple work of the informing the server to parse HTML as PHP. Some people complain of the load that this can put on the server, but I think this argument is unfounded.</p>
<p>What should be a simple solution, can often turn into an enormous problem. Things being what they are, we ran into a server where our simple two line .htaccess file failed to do the job. All manner of adjustments made between the .htaccess file, changes made by our server admin to the Apache httpd.conf file, all failed.</p>
<p>So in the event that these lines don&#8217;t work (while all of the Google results say that they do&#8230;)</p>
<p><span id="more-24"></span></p>

<div class="wp_codebox"><table><tr id="p2415"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p24code15"><pre class="div" style="font-family:monospace;">AddType application<span style="color: #44aa44;">/</span>x<span style="color: #44aa44;">-</span>httpd<span style="color: #44aa44;">-</span>php .html
AddHandler application<span style="color: #44aa44;">/</span>x<span style="color: #44aa44;">-</span>httpd<span style="color: #44aa44;">-</span>php .html</pre></td></tr></table></div>

<p> <br />
What we had to do instead was test to see if a version of the .html or .htm file existed. If it did, then our solution accessed that file as requested, if not, then it looks for a .php version of the same filename.</p>

<div class="wp_codebox"><table><tr id="p2416"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p24code16"><pre class="div" style="font-family:monospace;">RewriteEngine On
RewriteCond <span style="color: #44aa44;">%</span><span style="color: #44aa44;">&#123;</span>REQUEST_FILENAME<span style="color: #44aa44;">&#125;</span> <span style="color: #44aa44;">!-</span>f
RewriteRule <span style="color: #44aa44;">^</span><span style="color: #44aa44;">&#40;</span>.<span style="color: #44aa44;">+</span><span style="color: #44aa44;">&#41;</span><span style="color: #44aa44;">&#40;</span>\.htm|\.html<span style="color: #44aa44;">&#41;</span>$ $<span style="color: #cc66cc;">1</span>.php <span style="color: #44aa44;">&#91;</span>L<span style="color: #44aa44;">&#93;</span></pre></td></tr></table></div>

<p> <br />
In the end what you end up with is, no broken links in the search engines to the .html or .htm files and what everyone sees is the output of the .php file if the requested .html or .html file doesn&#8217;t exist.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.figmentthinking.com/2007/02/27/a-different-approach-to-parsing-html-as-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

