<?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>Feet Have Been &#187; PHP</title>
	<atom:link href="http://wheremy.feethavebeen.com/category/tutorials/php-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://wheremy.feethavebeen.com</link>
	<description>Sometimes, you just go where your feet take you</description>
	<lastBuildDate>Tue, 17 Aug 2010 13:40:50 +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>DataGrid Control V2</title>
		<link>http://wheremy.feethavebeen.com/2010/07/datagrid-control-v2/</link>
		<comments>http://wheremy.feethavebeen.com/2010/07/datagrid-control-v2/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 02:43:04 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Controls]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=400</guid>
		<description><![CDATA[I&#8217;ve been working on a series of &#8220;Control Objects&#8221; to include in my usual projects, and I thought I&#8217;d post one of the completed ones up here. Basically it mimcs the use of the DataGrid control in Visual Studio but in a way I find a lot easier and more in-tune with PHP. After creating [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a series of &#8220;Control Objects&#8221; to include in my usual projects, and I thought I&#8217;d post one of the completed ones up here. Basically it mimcs the use of the DataGrid control in Visual Studio but in a way I find a lot easier and more in-tune with PHP. After creating the DataGrid, you define a &#8220;source&#8221;. The Source is essentially a multi-dimensional array that you could assign with a simple</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>you would then pass $r as the source to the DataGrid. You have the ability to set some options (like specifying specific style sheets, JS libraries for AJAX editing or defining and renaming visible columns) and then a single build(); command will output the table. Of course, you can also build(true); to return the table incase you&#8217;re using some sort of theme system.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Angelo'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Rodrigues'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Darth'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Vader'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Luke'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Skywalker'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Han'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Solo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$DataGrid</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DataGrid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configure</span><span style="color: #009900;">&#40;</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'primary_key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'sortable'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'striped'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'even_row'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'odd_row'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'striped'</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This not only defines display fields, but the order as well </span>
<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
  <span style="color: #0000ff;">'f_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'First Name'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'l_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Last Name'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDisplayFields</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Headers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'css'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'js'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'object'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'js'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">source</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The code can be further simplified by using a new class called ControlObjectManager (or COM for short). COM can be used to instantiate multiple Controls at once and even assign shortcuts to commonly used Controls. For example, if you need DataGrids a lot, you can initiate them via a simple call like <code>$COM->init(array('dg'))</code> and as long as you set up that dg means DataGrid in the configuration for COM, you&#8217;re good to go. </p>
<p>I&#8217;ll post up some more on the COM when it&#8217;s done, but for now, here&#8217;s a link to the latest iteration of DataGrid v2. </p>
<p><a href="http://pastebin.com/nD969RJp">View on Pastebin</a> &#8211; Just note that this is the debug version of the script, so there are tons of comments and explanations.</p>
<p>The original DataGrid actually tied in to MySql directly and required the MySqlAdapter control to even function. This latest iteration removes all ties to any database instead focusing on a simple multi-dimensional array of data. As well it drops the code-base down quite a bit and condenses a lot of functionality. For example: originally you would have had to set the display columns and then order them, but by compressing them into a single function it not only makes MORE sense, but is easier to read.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2010/07/datagrid-control-v2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Default Config.php For All Your Projects</title>
		<link>http://wheremy.feethavebeen.com/2009/10/a-default-config-php-for-all-your-projects/</link>
		<comments>http://wheremy.feethavebeen.com/2009/10/a-default-config-php-for-all-your-projects/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 13:00:54 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=293</guid>
		<description><![CDATA[Wheneve rI start on a php project, I include the latest version of my config.php file from my Snippets section. This file contains my most commonly used functions and serve as the base from which I build whatever website/application I am working on. Instead of re-writing my config files differently for each application, I have [...]]]></description>
			<content:encoded><![CDATA[<p>Wheneve rI start on a php project, I include the latest version of my config.php file from my Snippets section. This file contains my most commonly used functions and serve as the base from which I build whatever website/application I am working on. Instead of re-writing my config files differently for each application, I have a common setup that works for me. Here&#8217;s what it looks like.</p>
<ul>
<li>Application Information</li>
<li>Variables</li>
<li>Functions</li>
</ul>
<p>It&#8217;s very simple and I&#8217;ve included all the code below with numerous comments, as well as included the config.php file for download.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * @file		Config.php
 * @description	contains all essential functions and configuration options
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Logging Directory
 */</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG_DIR'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'logs/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Enable Logging?
 */</span> 
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG'</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * The database variables below configure the different databases. 
 * To set the database use the $use variable
 *
 */</span>
<span style="color: #000088;">$db</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$db</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$db</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test_db'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$use</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Default class loader. To ensure single instances of each class, never initialize a class 
 * directly. Instead, use load_class(class_name) to initiate classes. 
 * 
 *  @param	string name of class to be loaded
 * 	@param	string path to class with trailing slash included
 *  @return	object reference to object
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #339933;">&amp;</span>load_class<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class</span><span style="color: #339933;">,</span><span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	static <span style="color: #000088;">$instance</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$class</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #000088;">$class</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #000088;">$class</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$class</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$class</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
			error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' does not exist in the Library'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Displays and optionally logs error messages
 * 
 * @param	string the message to be displayed
 * @param 	bool enables logging for particular message
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #000088;">$show</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">LOG</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> LOG_DIR<span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d_m_y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.log'</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'h:i:s a'</span><span style="color: #339933;">,</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>-<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$message</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$show</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;error&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$message</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The only things that I feel need some clarification is the load_class() function and the error() function. The load_class() function will accept two different arguments. The first one is necessary and is the name of the class to be loaded. The second is the path to the class. It is not required if the class is in the same directory as the page being run. You would use it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$myclass</span> <span style="color: #339933;">=</span> load_class<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myclass'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'path/to/class/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The error() function also accepts two arguments. The first is the message that you want to be logged. The second is whether or not to force the system to display that particular message. Remember, you can still display a message a not log it. Logging is based on the LOG variable that is defined near the beginning of the file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This error message will be logged only!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This error message will be logged AND displayed!'</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a href="http://wheremy.feethavebeen.com/uploads/Config.zip">Download The Config.php File from here!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/10/a-default-config-php-for-all-your-projects/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>mod_url without mod_url?</title>
		<link>http://wheremy.feethavebeen.com/2009/10/mod_url-without-mod_url/</link>
		<comments>http://wheremy.feethavebeen.com/2009/10/mod_url-without-mod_url/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 13:00:09 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=291</guid>
		<description><![CDATA[I know the title seems to make no sense but bear with me a minute. mod_url is an extension for the apache server that allows you to specify automatic routes for urls. So someone going to http://wheremy.feethavebeen.com/xangelo would see their profile page instead of going to http://wheremy.feethavebeen.com/profile?=xangelo It&#8217;s just a pretty way of formatting URLs. [...]]]></description>
			<content:encoded><![CDATA[<p>I know the title seems to make no sense but bear with me a minute. mod_url is an extension for the apache server that allows you to specify automatic routes for urls. So someone going to http://wheremy.feethavebeen.com/xangelo would see their profile page instead of going to http://wheremy.feethavebeen.com/profile?=xangelo It&#8217;s just a pretty way of formatting URLs. As an experiment, I decided to construct a handy little function that will allow you to parse links like http://wheremy.feethavebeen.com/index.php/profile/xangelo/view to create a more readable url structure.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> parse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #339933;">,</span><span style="color: #000088;">$self</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$e</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: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
				<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$t</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>To create a link to the same page the array key &#8216;base&#8217; can be used followed by a / and then the options you want. To create a link to my profile you could do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> parse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/profile/xangelo/view&quot;&gt;My Profile&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/10/mod_url-without-mod_url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Real-World OOP with PHP and MySQL</title>
		<link>http://wheremy.feethavebeen.com/2009/10/real-world-oop-with-php-and-mysql/</link>
		<comments>http://wheremy.feethavebeen.com/2009/10/real-world-oop-with-php-and-mysql/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 14:00:40 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[net]]></category>
		<category><![CDATA[tuts]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=198</guid>
		<description><![CDATA[Check out an in depth tutorial covering Object Oriented design practices through the development of your own MySQL interaction object using PHP. It's a mouthful, but it takes you from know OOP knowledge to a working OOP application.]]></description>
			<content:encoded><![CDATA[<p>Due to actual copyright constraints I can&#8217;t post the actual contents of this tutorial up here, but I can post the excerpt and provide you with a link to check it out, just click the image to head over to <a href="http://net.tutsplus.com/">Net-Tuts</a> and check it out</p>
<p><a href="http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/"><img class="aligncenter size-full wp-image-199" title="Nettuts - Real World OOP" src="http://wheremy.feethavebeen.com/wp-content/uploads/2009/10/Screenshot1.png" alt="Nettuts - Real World OOP" width="633" height="216" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/10/real-world-oop-with-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preserve query strings</title>
		<link>http://wheremy.feethavebeen.com/2009/10/preserve-query-strings/</link>
		<comments>http://wheremy.feethavebeen.com/2009/10/preserve-query-strings/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 21:49:09 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=184</guid>
		<description><![CDATA[As you keep developing your website, you&#8217;ll notice that occasionally you&#8217;ll need to keep track of more than one query string at a time. Eventually, you&#8217;ll find that this gets to be such a task in itself, you&#8217;ll wish there was an easier way to do it. That is what the preserve_links() function does. It [...]]]></description>
			<content:encoded><![CDATA[<p>As you keep developing your website, you&#8217;ll notice that occasionally you&#8217;ll need to keep track of more than one query string at a time. Eventually, you&#8217;ll find that this gets to be such a task in itself, you&#8217;ll wish there was an easier way to do it. That is what the preserve_links() function does. It takes the url, grabs all the query strings, updates the query string based on what you want, and then uploads it all.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000000; font-weight: bold;">function</span> preserve_links<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option</span><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: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">.</span><span style="color: #000088;">$option</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'='</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keys</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$option</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'='</span><span style="color: #339933;">.</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see it&#8217;s fairly straight forward. You pass the query string you want to set as the arguments. It doesn&#8217;t matter if the query string is one that is already present in the url as it will be overwritten. For example if your url is:</p>
<p>index.php?page=4&amp;id=12</p>
<p>running the command preserve_links(&#8216;page&#8217;,5); will generate the string of index.php?page=5&amp;id=12</p>
<p>If you wish to append a query string preserve_links(&#8216;session&#8217;,38581); will generate a url of index.php?session=38581&amp;page=5&amp;id=12</p>
<p>It&#8217;s a quick nifty little function that saves you a lot of headaches!</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/10/preserve-query-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple query strings</title>
		<link>http://wheremy.feethavebeen.com/2009/09/simple-query-strings/</link>
		<comments>http://wheremy.feethavebeen.com/2009/09/simple-query-strings/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 04:59:20 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=159</guid>
		<description><![CDATA[Often times a developer will want to pass a piece of information between pages on his website. While the most desirable method to do this is via a form, sometime this just isn&#8217;t possible. During these times, it&#8217;s time to turn to query strings. Query strings are a bit of a confusing concept, mostly because [...]]]></description>
			<content:encoded><![CDATA[<p>Often times a developer will want to pass a piece of information between pages on his website. While the most desirable method to do this is via a form, sometime this just isn&#8217;t possible. During these times, it&#8217;s time to turn to query strings.</p>
<p>Query strings are a bit of a confusing concept, mostly because of their name. If you ignore the terminology, it is just a way for you to pass information between pages on a website <span style="text-decoration: underline;">using the url.</span> This is the key to Query strings. They make your url go from this</p>
<p><em>index.php</em></p>
<p>to this:</p>
<p><em>index.php?q1=something&amp;q2=somethingelse</em></p>
<p>And that&#8217;s all a query string is. When a user sees a link like that in the location bar in their browser what they are really seeing is<em> index.php</em> but with a little added information passed to it.</p>
<p><strong>How do you do it?</strong></p>
<p>Creating query strings is ridiculously simple. Say you want to pass an id to <em>news.php</em>. You would like it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;index.php?id=4&quot;&gt;Link to index.php with id 4&lt;/a&gt;</pre></div></div>

<p>If you wanted to pass an id and another value, you would do it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;index.php?id=4&amp;another=value&quot;&gt;Link to index.php with id 4 and another value&lt;/a&gt;</pre></div></div>

<p>And that&#8217;s it. If a user clicks on that link they will be directed to <em>index.php</em> with your query string attached!</p>
<p><strong>How do I get that information?</strong></p>
<p>Writing the query string, of course, is only half the battle. The other half is actually reading that query string. This is where the <a href="http://ca2.php.net/manual/en/reserved.variables.get.php">$_GET</a> array comes into play. $_GET is built into PHP and provides you access to the values after the ? in query strings. Since $_GET is an array, the key that you will use to access your values, are their names!</p>
<p>A little confusing, but let me give you a quick breakdown using one of our query strings:</p>
<p>key = id<br />
value = 4</p>
<p>So that means, to get that value 4, we would need to use $_GET['id'].</p>
<p>If we follow that logic, then to get the value of &#8220;another&#8221; we would use $_GET['another'].</p>
<p><strong>Summary</strong></p>
<p>Query strings are a little confusing until you realize that they&#8217;re just a way of passing variables through the url.</p>
<p>Still confused? Post your questions in the comments or send me an email!</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/09/simple-query-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to MySQL and PHP</title>
		<link>http://wheremy.feethavebeen.com/2009/09/introduction-to-mysql-and-php/</link>
		<comments>http://wheremy.feethavebeen.com/2009/09/introduction-to-mysql-and-php/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 20:12:54 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=152</guid>
		<description><![CDATA[I&#8217;ve been working with PHP for so long I&#8217;ve forgotten what it was like when you&#8217;re just starting out. Things to me like appending strings to form complex sql queries were things that I struggled with when I first started out. The idea seemed to be very simple, but without understanding exactly what was happening, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with PHP for so long I&#8217;ve forgotten what it was like when you&#8217;re just starting out. Things to me like appending strings to form complex sql queries were things that I struggled with when I first started out. The idea seemed to be very simple, but without understanding exactly what was happening, it quickly spiraled out into something that made absolutely no sense.</p>
<p>Here is the the problem. We have a database consisting of the following fields: </p>
<ul>
<li>id – a unique identifier of an entry</li>
<li>name – a persons’ name</li>
<li>address – their address</li>
<li>city – the city they live in</li>
<li>state – the state they live in</li>
</ul>
<p>The database may contain anywhere from 5 to 5000 entries, it doesn’t matter. We still have to figure out a way to display only what the user requires. For example, if the user only wants to see people who live in a certain city, they should be able to filter by city. Perhaps they want to see only the people in a certain state, then they should be able to filter by state. </p>
<p><strong>The Pseudo-code</strong></p>
<p>I find this is an important part to coding a solution to our problem. Understanding exactly how you will do it is essential. We are going to only have one page and let the user select which state/city they wish to use from a simple form and then let them filter the results like that. Instead of having multiple pages we are also going to have all our code in one file. The code will look like the following</p>
<ol>
<li>Create a default SQL statement</li>
<li>Get any filters</li>
<li>Update SQL statement with filters</li>
<li>Display the results</li>
</ol>
<p>Before we get to the PHP part, we’re going to first design the HTML part of our page. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Selecting Certain Information<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=<span style="color: #006699; font-weight: bold;">$_SERVER</span>['PHP_SELF']?&amp;gt;&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #990000;">Sort</span> By<span style="color: #339933;">:</span> 
<span style="color: #339933;">&lt;</span>select name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;city&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> selected<span style="color: #339933;">&gt;-----&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;city1&quot;</span><span style="color: #339933;">&gt;</span>City <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;city2&quot;</span><span style="color: #339933;">&gt;</span>City <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;city3&quot;</span><span style="color: #339933;">&gt;</span>City <span style="color: #cc66cc;">3</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>select name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;state&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> selected<span style="color: #339933;">&gt;-----&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;s1&quot;</span><span style="color: #339933;">&gt;</span>State <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;s2&quot;</span><span style="color: #339933;">&gt;</span>State <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;s3&quot;</span><span style="color: #339933;">&gt;</span>State <span style="color: #cc66cc;">3</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>button type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span><span style="color: #339933;">&gt;</span>Filter<span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Notice that our states and cities are present in a dropdown element. The value of each element corresponds to how it is stored in the database. For example if the state of Nebraska is stored as NE in the database, the value for Nebraska in the form should be NE. </p>
<p>We are assuming that you have already connected to your database somewhere near the start of your script. Step one is to create the default sql statement. After our form, we are going to add this snippet of code</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'select * from table'</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now we are going to get the filters. Notice that we are using the $_POST array which is built into PHP and can access forms that are submitted using the $_POST method. Since we are trying to access the form elements named “city” and “state” those are the keys in our $_POST array. $_POST[‘city’] and $_POST[‘state’]. We are also going to go one step further and pass the values of that to two different functions. These functions will essentially make any user-input safe to use. You can read up more on addslashes() and strip_tags() in the PHP manual. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'city'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$state</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'state'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now it’s time to update our SQL statement based on the filters. First we are going to check to make sure that City and State are not empty. If they are, we don’t need to update our sql statement and we can just run it. If they are not, then we will need to deal with each one separately. </p>

<div class="wp_syntax"><div class="code"><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><span style="color: #000088;">$city</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$state</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$city</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$state</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The reason we are doing it this way is because of how the logic behind IF statements works. It will first check both $city and $state and if they are both NOT empty, it will execute the first block of code. If either one is empty, it will skip that block and move on to the next. If $city is empty, then it will skip that block and move on to the last. If $state is empty, it won’t do anything. The reason we want to check to make sure that $state is empty instead of just assuming it is because you should never assume when it comes to your users. They will always do things that you never assumed they did. This is a failsafe to make sure that only the values you are allowing will get through. </p>
<p>If the user selected both a city and a state our new sql statement will look like this: </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' where city = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$city</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; and state = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$state</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The .= in PHP is concatenation. Basically it is just appending the WHERE clause to our default SQL statement. This way our sql statement is now </p>
<p>‘select * from table where city = “’.$city.’” and state = ‘”.$state.’”’ </p>
<p>That will select only the values from the database that match both the city and state filters. </p>
<p>In the second block, we are dealing with if only a city was specified. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' where city = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$city</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see, it’s almost the same thing, just with the bit about state removed. </p>
<p>The last block is almost exactly the same as the one before, just instead of city, we are dealing with state</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' where state = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$state</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And finally we run our query. </p>
<p>Now you can proceed to handle the results however you wish. If you already have code that was handling the results, you can keep using that as that will remain the same. The only thing that changes is the SQL statement itself, which will dictate what results SQL will take from the database and give back to us. </p>
<p>Here&#8217;s the complete page code</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Selecting Certain Information&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;&amp;lt;?=$_SERVER['PHP_SELF']?&amp;gt;&quot; method=&quot;post&quot;&gt;
Sort By: 
&lt;select name=&quot;city&quot;&gt;
&lt;option value=&quot;&quot; selected&gt;-----&lt;/option&gt;
&lt;option value=&quot;city1&quot;&gt;City 1&lt;/option&gt;
&lt;option value=&quot;city2&quot;&gt;City 2&lt;/option&gt;
&lt;option value=&quot;city3&quot;&gt;City 3&lt;/option&gt;
&lt;/select&gt;
 &lt;select name=&quot;state&quot;&gt;
&lt;option value=&quot;&quot; selected&gt;-----&lt;/option&gt;
&lt;option value=&quot;s1&quot;&gt;State 1&lt;/option&gt;
&lt;option value=&quot;s2&quot;&gt;State 2&lt;/option&gt;
&lt;option value=&quot;s3&quot;&gt;State 3&lt;/option&gt;
&lt;/select&gt;
 &lt;button type=&quot;submit&quot;&gt;Filter&lt;/button&gt;
&lt;/form&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'select * from table'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'city'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$state</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'state'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$city</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$state</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' where city = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$city</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; and state = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$state</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$city</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' where city = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$city</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$state</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' where state = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$state</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>If you have any questions, feel free to leave a comment or even email me. </p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/09/introduction-to-mysql-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excerpt</title>
		<link>http://wheremy.feethavebeen.com/2009/08/excerpt/</link>
		<comments>http://wheremy.feethavebeen.com/2009/08/excerpt/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 15:05:37 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=146</guid>
		<description><![CDATA[When you start about building your own blogging/CMS systems, you&#8217;ll normally run into the need for an excerpt system. Sure you could use a whole new field in your database to handle it, but sometimes, it&#8217;s just easier to grab a bit of text from your post and use that. However, doing it so that [...]]]></description>
			<content:encoded><![CDATA[<p>When you start about building your own blogging/CMS systems, you&#8217;ll normally run into the need for an excerpt system. Sure you could use a whole new field in your database to handle it, but sometimes, it&#8217;s just easier to grab a bit of text from your post and use that.</p>
<p>However, doing it so that you don&#8217;t cut off mid word can be a bit of a challenge. Luckily for us, PHP has a few great functions, that while on their own seem fairly useless, combined gives us exactly what we are looking for.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&amp;lt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> excerpt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_int</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #cc66cc;">100</span><span style="color: #339933;">:</span><span style="color: #000088;">$size</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$message</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' ...'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This function will accept the string you want to make an excerpt out of as well as an optional size variable. This will tell us how large we want the excerpt to be. Because of the nature of this function, the resulting excerpt will not always be 100 characters, but it will be as close as it can to it without going over.</p>
<p>The first check we do is to make sure that the size passed to our function is actually an integer. If it is not, then we simply set it back to our default of 100. These are known as conditional statements, and if we broke it out it would really just be</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_int</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">else</span>
	<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #339933;">;</span></pre></div></div>

<p>Which is just too long for what we need.</p>
<p>The next line actually takes our string and chops it off at 100 characters using the <a href="http://us2.php.net/manual/en/function.substr.php">substr()</a> function. Using this function we pass our string as the first parameter, the start location (0 in this case, because we want to start at the beginning of the string) and the length of the string we need.</p>
<p>The last line of our function is a little more complicated than the rest. Once again we are using the substr() function, but this time as our third argument is actually the position of the last occurring &#8221; &#8221; (space) in our new substring. This is done using the built in function <a href="http://us2.php.net/manual/en/function.strrpos.php">strrpos() </a>This function takes a string, and a delimiter, and looks for the limiter starting at the end of the string. If it encounters it, it returns an integer value of its position. This ensures that the last character is actually a space.</p>
<p>Finally we return the new $message value.</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=b65598eb-6ec0-82c3-b389-4f32490bd4d2" alt="" /></div>
<p class="scribefire-powered">Powered by <a href="http://www.scribefire.com/">ScribeFire</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/08/excerpt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verbose Arguments</title>
		<link>http://wheremy.feethavebeen.com/2009/06/verbose-arguments/</link>
		<comments>http://wheremy.feethavebeen.com/2009/06/verbose-arguments/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 04:59:11 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[verbose arguments]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=112</guid>
		<description><![CDATA[Imagine if you will, reading an instruction manual that went a little like this Place 3b into 2c while holding 4d adjacent to panel a4. Now, any normal person will have absolutely no idea what&#8217;s being talked about. And that&#8217;s ok, because there isnt any kind of legend included within. For example, if I included [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine if you will, reading an instruction manual that went a little like this</p>
<blockquote><p>Place 3b into 2c while holding 4d adjacent to panel a4.</p>
</blockquote>
<p>Now, any normal person will have absolutely no idea what&#8217;s being talked about. And that&#8217;s ok, because there isnt any kind of legend included within. For example, if I included a legend like the following, you would have no trouble understanding what I was talking about.</p>
<blockquote><p>a4: Cabinet Side Wall<br />
2c: Hole on bottom left of Cabinet Side<br />
3b: Screw<br />
4d: Cabinet Door</p>
</blockquote>
<p>Hey now, magically that all makes sense. And in an instruction manual, where you have a set number of components, it&#8217;s alright to include things in an abbreviated manner.</p>
<p>But why would you apply the same logic to code? Why would you force variables into concise statements when it would make more sense to expand them? After all, L1 makes less sense than Line1 does right? This logic works great for variables, but fails a little when you move to function arguments. Essentially, the very fact that it is great for describing what a variables&#8217; use is, causes it to be large, and accumulating upwards of 2 or 3 of these verbose variables into a function can become tedious. No one wants to read two or three lines of function arguments.</p>
<p>While thinking about the matter on a recent project that I have been working on, I realized that many frameworks had already stumbled upon the problem, and solved it rather quickly. The idea is that in a function, we can leave room for a variable length of arguments for any function, and still have &#8220;required&#8221; values. It is a little complicated but in a code example, we can see the value of such an idea:</p>
<p>Way 1: Concise<br />
function call($var1, $var2,$var3,$var4,$var5)<br />
{</p>
<p>}</p>
<p>Way 2: Verbose<br />
function call($var)<br />
{</p>
<p>}</p>
<p>No it isn&#8217;t a typo, Way 2, the Verbose way really does have only one argument, but it will be treated as an array. Not a regular array, because those are messy looking in practice, but a string separated by both colons and commas and returned to the function. The bonus of this is that when you go about developing an application, you can see what variables a function requires at a glance.</p>
<p>Concise Argument Definition:<br />
call(135,12331,123,41344,384192&#8242;);</p>
<p>Verbose Argument Definition:<br />
call(&#8216;takeout: 135, initial: 12331, custid: 123, accountid: 41344, custphone: 384192&#8242;);</p>
<p>Now you can clearly see why they are called verbose arguments, but also why we would use them. When perusing your code after a few days, you seldom remember what a badly named variable does. In this way, you can, at a glance, see what variables a function will accept and you can define them in any way. In the first example, if 135 and 12331 were switched, you would get an error since you can&#8217;t subtrace 12331 from 135 without resulting in a negative number. However, with verbose arguments, you can&#8217;t go wrong. You can easily see what you are setting each argument to, and you can easily set things right, incase you mess up.</p>
<p>One could obviously argue that the same method can be achieved using arrays, but arrays are ugly, and since programming is an art form, we try and stay away from ugly.</p>
<p>As for verbose arguments, they are definitely a welcome addition to any piece of software, and it is well worth the few extra minutes of programming to cobble together a quick function that will handle everything for you. The function will take a string verbose input, and split it according these rules, and return the new array back.</p>
<p><strong>Rules<br />
</strong></p>
<ul>
<li>Variable names are before a colon.</li>
<li>There must be no space between the variable name and the colon (ie. varname: is acceptable but varname : is not)</li>
<li>The value for a variable must come after the variable (with or without a space)</li>
<li>Multiple variables are separated with a comma after the variable value (ie. varname1: angelo, varname2: another)</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> parse_args<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #000088;">$num_e</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$num_e</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">': '</span><span style="color: #339933;">,</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
					<span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">,</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Parse to array[key] = value format</span>
		<span style="color: #000088;">$num_args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$num_args</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tmp</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</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: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$tmp</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hopefully, after incorporating it into your own applications you&#8217;ll see the benefit of something like this. </p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/06/verbose-arguments/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
