<?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>Dev Tips &#124; Become a Better Developer, One Tip at a Time. &#187; PHP</title>
	<atom:link href="http://dev-tips.com/category/server-side/php/feed" rel="self" type="application/rss+xml" />
	<link>http://dev-tips.com</link>
	<description>Become a Better Developer, One Tip at a Time.</description>
	<lastBuildDate>Sun, 07 Mar 2010 02:19:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Creating Unique Styles for WordPress Pages</title>
		<link>http://dev-tips.com/featured/creating-unique-styles-for-wordpress-pages</link>
		<comments>http://dev-tips.com/featured/creating-unique-styles-for-wordpress-pages#comments</comments>
		<pubDate>Sun, 07 Mar 2010 02:07:23 +0000</pubDate>
		<dc:creator>Nick Plekhanov</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=893</guid>
		<description><![CDATA[In WordPress 2.8, there is one small but very useful feature, both for WP web developers, and for bloggers. This is an opportunity to change the appearance of any individual page or group of pages without the need to write either the functions/conditions on php or install plugins. All you need to do is simply [...]]]></description>
			<content:encoded><![CDATA[<p>In WordPress 2.8, there is one small but very useful feature, both for WP web developers, and for bloggers. This is an opportunity to change the appearance of any individual page or group of pages without the need to write either the functions/conditions on php or install plugins. All you need to do is simply add your desired style to your css file.</p>
<p><span id="more-893"></span></p>
<h2>How does it work? </h2>
<p>In WordPress 2.8 has been added to the function <code>body_class()</code>. It works like so</p>
<pre class="brush: php">
&lt;body &lt;?php body_class(); ?&gt;&gt;
</pre>
<p> So, we just need to apply such function to the body.</p>
<p>If your theme is adapted for WordPress 2.8, this feature is probably already present in the code. In case you can’t find that function, it's enough to search for
<pre class="brush: html">&lt;body&gt;</pre>
<p> tag in <code>header.php</code> file of your theme and replace it with </p>
<pre class="brush: php">
&lt;body &lt;?php body_class(); ?&gt;&gt;
</pre>
<h2>Usage</h2>
<p>What do we get from using this function? It’s very simply; we get a &lt;body&rt; tag with additional classes, such as:<br />
&lt;body class="home blog"&rt;<br />
or<br />
&lt;body class=" single postid-1001 parent-page-id-0 page-template-default"&rt;</p>
<p>What does this give us? Let’s look at some examples.</p>
<p>Adding to your website’s css file:</p>
<pre class="brush: css">
.postid-3 #respond{

display: none; 

}
</pre>
<p>Will kill comments form from post with id=3, just leaving comments.</p>
<hr />
<pre class="brush: css">
.home{

background: #f00;

}
</pre>
<p>Only make the background of the home page in red.</p>
<hr />
<pre class="brush: css">
.page h2{

font-size: 30px;

}
</pre>
<p>Increases the size of the header only on the pages (not blog entries) of the site.</p>
<p>Anyway, these are just simple examples. Using this feature you can make almost any changes in the CSS file for a single page or page group.</p>
<h2>Documentation</h2>
<p>Below you can see a full list of body classes that can be used for custom styling (just apply desired styles to them). That long list lets us know that style can be applied to almost any page, even to the third page of a search results, even to the tag, even to the author.</p>
<ul>
<li>rtl </li>
<li>home </li>
<li>blog </li>
<li>archive </li>
<li>date </li>
<li>search </li>
<li>paged </li>
<li>attachment </li>
<li>error404 </li>
<li>single postid-(id)</li>
<li>attachmentid-(id) </li>
<li>attachment-(mime-type) </li>
<li>author </li>
<li>author-(name) </li>
<li>category </li>
<li>category-(name) </li>
<li>tag </li>
<li>tag-(name) </li>
<li>page</li>
<li>page-parent </li>
<li>page-child parent-pageid-(id) </li>
<li>page-template page-template-(template file name) </li>
<li>search-results </li>
<li>search-no-results</li>
<li>logged-in </li>
<li>paged-(page number) </li>
<li>single-paged-(page number) </li>
<li>page-paged-(page number) </li>
<li>category-paged-(page number) </li>
<li>tag-paged-(page number) </li>
<li>date-paged-(page number) </li>
<li>author-paged-(page number) </li>
<li>search-paged-(page number)</li>
</ul>
<p>For WordPress huge fans and those who wants more, there is an opportunity to add their custom classes to body_class via a standard WordPress way:</p>
<pre class="brush: php">
&lt;?php
add_filter(&#039;body_class&#039;,&#039;my_body_classes&#039;);
function my_body_classes($classes, $class) {
	// add &#039;my-class&#039; to the $classes array
	$classes[] = &#039;my-class&#039;;
	// return the $classes array
	return $classes;
}
?&gt;
</pre>
<p>There is no official documentation for body_class() at the moment, but as usually happens in WordPress, the function is made very simply and wisely. So, it is not difficult to understand it. A little more details can be found in the body_class() function’s code.</p>
<p>Thank you and good luck! <img src='http://dev-tips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/creating-unique-styles-for-wordpress-pages/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP For Absolute Beginners Reviewed + Giveaway!</title>
		<link>http://dev-tips.com/featured/php-for-absolute-beginners-reviewed-giveaway</link>
		<comments>http://dev-tips.com/featured/php-for-absolute-beginners-reviewed-giveaway#comments</comments>
		<pubDate>Tue, 08 Dec 2009 09:34:39 +0000</pubDate>
		<dc:creator>Drew Douglass</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Server Side]]></category>
		<category><![CDATA[Book Review]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=682</guid>
		<description><![CDATA[Recently, fellow web developer and friend, Jason Lengstorf wrote and published (by Apress Publishing) PHP for Absolute Beginners. Jason was kind enough to send me a copy for my own reading and enjoyment. Now that I've finished, I'll be quickly reviewing the book and then giving away a free copy to one of our readers, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, fellow web developer and friend, <a href='http://ennuidesign.com/' title='Ennui Design'>Jason Lengstorf</a> wrote and published (by Apress Publishing) <a href="http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738">PHP for Absolute Beginners.</a><img src="http://www.assoc-amazon.com/e/ir?t=devtips-20&#038;l=as2&#038;o=1&#038;a=1430224738" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
<p> Jason was kind enough to send me a copy for my own reading and enjoyment. Now that I've finished, I'll be quickly reviewing the book and then giving away a free copy to one of our readers, courtesy of Jason Lengstorf and Apress Publishing! Read on to find out more about the book and how to win the giveaway!
</p>
<p><span id="more-682"></span></p>
<div><a href='http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738' title='PHP For Absolute Beginners Review and Giveaway'><img alt="" src="http://dev-tips.com/post_img/php_absolute_review_image.png" title="PHP For Absolute Beginners Review and Giveaway!" class="aligncenter" width="370" height="457" /></a></div>
<p><a href='http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738'>You can grab the book on Amazon</a> right now as an early Christmas or Holiday gift to yourself, and start learning php today!</p>
<h2>Overall Thoughts</h2>
<p>The book was awesome, seriously, it was awesome. I say this as someone who has already had a lot of experience working with php, in fact, I make most of my living writing PHP code.</p>
<p>Don't believe me eh? It's so good, I gave it one thumb up! <strong>It would have gotten two</strong>, but I needed one hand to hold it:</p>
<div><div id="attachment_696" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738"><img src="http://dev-tips.com/wp-content/uploads/2009/12/Photo-47-300x225.png" alt="Drew Approves of This Book" title="PHP For Absolute Beginners Book" width="300" height="225" class="size-medium wp-image-696" /></a><p class="wp-caption-text">Drew Approves of This Book</p></div></div>
<h2>Target Audience</h2>
<p>Mostly beginners, but can be used as a great refresher or reference book for intermediate to advanced users.</p>
<p><strong>Do not let the title fool you, this book is no small book!</strong> <em><a href='http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738'>PHP For Absolute Beginners</a></em> is quite a chunky book, filled with useful information and sample tutorials. Towards the last half of the book, you are walked step by step through building a nice web application.</p>
<p>If you're looking to get started with php, hands down this is the book you want to pick up first. It is not too overwhelming while at the same time stays extremely informative and in depth.</p>
<h2>Topics I Found Useful</h2>
<p>While there are a ton of valuable resources and topics in the book, a few of them stuck out to me as great references and guides:</p>
<ul>
<li>MySQLi Refresher and References</li>
<li>PDO (PHP Data Objects) and DB Abstraction is taught step by step and encouraged.</li>
<li>PHP security and best practices are dealt with immediately.</li>
<li>Great XML and RSS Feed section.</li>
</ul>
<h2>Want a Free Copy?</h2>
<p>We're giving away a copy of <em><a href='http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738'>PHP For Absolute Beginners</a></em> absolutely free! Read the details below to find out how to win!</p>
<ul>
<li>Make a quick tweet about this giveaway/review on Twitter, please include the hashtag <code>#DevTipsGiveaway</code> in your tweet. Here is a short URL to the post you can use - <code>http://bit.ly/6AJ46T</code></li>
<li>Leave a comment with one reason why you would like to win this book. Be sure you enter a valid email address so we can reach you if you win.</li>
<li>That's it, we'll announce the winner a week or two afterward!</li>
</ul>
<h2>Get the Book Now!</h2>
<p>Want to get started learning PHP the right way? Go ahead and <a href='http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738'>grab the book now</a>, it's definitely a great book to have on hand!</p>
<div><a href='http://www.amazon.com/gp/product/1430224738?ie=UTF8&#038;tag=devtips-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1430224738' title='Get PHP For Absolute Beginners'><img alt="" src="http://dev-tips.com/post_img/php_absolute_get_now.png" title="Get PHP For Absolute Beginners Now!" class="aligncenter" width="369" height="454" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/php-for-absolute-beginners-reviewed-giveaway/feed</wfw:commentRss>
		<slash:comments>74</slash:comments>
		</item>
		<item>
		<title>How To Create Your First AJAX and PHP Contact Form</title>
		<link>http://dev-tips.com/featured/ajax-and-php-contact-form</link>
		<comments>http://dev-tips.com/featured/ajax-and-php-contact-form#comments</comments>
		<pubDate>Mon, 02 Nov 2009 12:38:24 +0000</pubDate>
		<dc:creator>Drew Douglass</dc:creator>
				<category><![CDATA[Downloads]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Server Side]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=586</guid>
		<description><![CDATA[You've been to websites that use them, a nice little AJAX contact form. AJAX is a great way to submit data without a page refresh and is a great tool for certain elements of a website, such as a contact form. So how do we go about doing so? Today, we will take it step [...]]]></description>
			<content:encoded><![CDATA[<p>You've been to websites that use them, a nice little AJAX contact form. AJAX is a great way to submit data without a page refresh and is a great tool for certain elements of a website, such as a contact form. So how do we go about doing so? Today, we will take it step by step and build your first AJAX and PHP contact form. We'll be using <a href='http://jquery.com' title='jQuery Javascript Library'>jQuery</a> and the popular <a href='http://code.google.com/p/php-email-address-validation/' title='Email Validation'>email validation code</a> found on google code (originally by AddedBytes) to help us out.</p>
<p><span id="more-586"></span><br />
<img src="http://dev-tips.com/wp-content/uploads/2009/11/php_ajax_form.png" alt="php_ajax_form" title="php_ajax_form" width="605" height="220" class="aligncenter size-full wp-image-635" /></p>
<h2 class='box demo'><a target='_blank' href='http://dev-tips.com/demo/ajax_contact_form/index.html' title='Live AJAX Contact Form Demo'>Live Demo</a></h2>
<div class='download_orange'><a class="downloadlink" href="http://dev-tips.com/wp-content/plugins/download-monitor/download.php?id=4" title="Version 1.0 downloaded 1388 times" >Ajax_Contact_Form (1388) - 5.68 KB</a></div>
<h2>Folder Structure and Files</h2>
<p>Here is a brief overview of how we will setup our folders and files. If you are following along, you can go ahead and create all of these now, we'll get to them all one by one.</p>
<p>Below is the folder structure and files contained within:</p>
<ul>
<li><strong>assets</strong>
<ul>
<li><strong>css</strong>
<ul>
<li><em>style.css</em></li>
</ul>
</li>
<li><strong>js</strong>
<ul>
<li><em>ajax.js</em></li>
</ul>
</li>
<li><strong>php</strong>
<ul>
<li><em>contact-send.php</em></li>
<li><em>email-validator.php (will be downloaded and added later on)</em></li>
</ul>
</li>
<li>index.html</li>
</ul>
</ul>
<h2>HTML and Form Markup</h2>
<p>Now we need our HTML and form markup. We will try to keep it relatively simple.</p>
<h3>index.html</h3>
<pre class="brush: html">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;/&gt;
	&lt;title&gt;Your First AJAX and PHP Contact Form - Live Demo&lt;/title&gt;

	&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;assets/js/ajax.js&quot;&gt;&lt;/script&gt;
	&lt;link rel=&quot;stylesheet&quot; type=&#039;text/css&#039; href=&#039;assets/css/style.css&#039; media=&#039;screen&#039; /&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;div id=&#039;wrap&#039;&gt;
		&lt;div id=&#039;header&#039;&gt;
			&lt;h1&gt;Get in touch with us...&lt;/h1&gt;
			&lt;h2&gt;Use the form below to try out the contact form.&lt;/h2&gt;
		&lt;/div&gt;

		&lt;form method=&#039;post&#039; action=&#039;./assets/php/contact-send.php&#039;&gt;
		&lt;fieldset&gt;
			&lt;legend&gt;Contact Us&lt;/legend&gt;
			&lt;label for=&#039;name&#039;&gt;Name (required)&lt;/label&gt;
				&lt;input id=&#039;form_name&#039; type=&#039;text&#039; name=&#039;name&#039; value=&#039;&#039; /&gt;
			&lt;label for=&#039;email&#039;&gt;Email (required)&lt;/label&gt;
				&lt;input id=&#039;form_email&#039; type=&#039;text&#039; name=&#039;email&#039; value=&#039;&#039; /&gt;
			&lt;label for=&#039;subject&#039;&gt;Subject&lt;/label&gt;
				&lt;input id=&#039;form_subject&#039; type=&#039;text&#039; name=&#039;subject&#039; value=&#039;&#039; /&gt;
			&lt;label for=&#039;message&#039;&gt;Message (required)&lt;/label&gt;
				&lt;textarea id=&#039;form_message&#039; rows=&#039;10&#039; cols=&#039;40&#039; name=&#039;message&#039; value=&#039;&#039;&gt;&lt;/textarea&gt;

			&lt;input id=&#039;form_submit&#039; type=&#039;submit&#039; name=&#039;submit&#039; value=&#039;Submit&#039; /&gt;

			&lt;p class=&#039;hide&#039; id=&#039;response&#039;&gt;&lt;/p&gt;

			&lt;div class=&#039;hide&#039;&gt;
				&lt;label for=&#039;spamCheck&#039;&gt;Do not fill out this field&lt;/label&gt;
				&lt;input name=&#039;spam_check&#039; type=&#039;text&#039; value=&#039;&#039; /&gt;
			&lt;/div&gt;
		&lt;/fieldset&gt;
		&lt;/form&gt;

	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Everything above should look pretty standard, you'll notice we have a weird input and label towards the bottom of the form. We will be using this as a very basic spam check later on. More on that in a bit.</p>
<p>Also take note we are importing jQuery, our soon to be created <code>ajax.js</code>, and our <code>style.css</code>.</p>
<h2>Styles</h2>
<p>I'll leave the styles up to you, here is the bare minimum. The only thing we really need to make sure is that we hide anything inside the div class of <code>hide</code>. Notice we have still typed<br />
<blockquote>Do not fill out this field</p></blockquote>
<p>. We've done so in the very rare chance someone is surfing without CSS, they will know to leave the field blank.</p>
<h3>style.css</h3>
<pre class="brush: css">
#wrap {
	margin:0 auto;
	width:960px;
}
.hide {
	display: none;
}
label {
	display:block;
}
input {
	display:block;
}
</pre>
<h2>The PHP Code</h2>
<p>If you need to brush up on your php skills check out <a href='http://dev-tips.com/featured/5-more-quality-sites-to-help-you-become-a-php-rockstar'>5 more quality sites to help you become a php rockstar</a></p>
<h3>A word about email validation</h3>
<p><strong>You will need to download a file before I go any further</strong>, you can download the <a href='http://code.google.com/p/php-email-address-validation/'>google email validation script here</a>.</p>
<p>Got it downloaded? Great! Name it <code>email-validator.php</code> and put it in your php folder you created.</p>
<p>Now, a word about email validation. It is tricky business to say the least. There are hundreds if not thousands of little tiny things to take into account. I recently wrote a blog post titled <a href='http://php-tips.net/validate-email-with-php-the-right-way/' title='The right way to validate an email address with php'>The right way to validate an email address with php.</a> In hindsight, thhe technique used in that post certainly works, but isn't without it's draw backs. <code>FILTER_VALIDATE_EMAIL</code> has known bugs and only runs on newer versions of php, so this isn't an option for a lot of people.</p>
<p>Tired yet? Bare with me.</p>
<p>This is where the <a href='http://code.google.com/p/php-email-address-validation/'>google code email validation script</a> we downloaded comes in to play. It <a href='http://www.addedbytes.com/php/email-address-validation/'>originally aired</a> on the well known site <a href='http://addedbytes.com'>AddedBytes.com</a>. It has since grown in popularity so much that it has been moved to google code where it has received hundreds of contributions from members around the world, all with a goal to build a very solid and quick email validation system.</p>
<p>In short, <strong>the google email validation script kicks ass and we are going to use it.</strong></p>
<h3>Back to the main php code</h3>
<p>Now is where we let the php do the heavy lifting. If you haven't already created your <code>contact-send.php</code> file, see the structure above and do so now.</p>
<p>I have left many comments in the code below, so be sure to read through them. I'll go through a few important bullet points after.</p>
<h3>contact-send.php</h3>
<p><small><strong>Editors note:</strong> Please ignore any duplicate <code>empty</code> function calls below, this is a known bug of the syntax highlighting plugin. You can always download the source files if you have any confusion.</small></p>
<pre class="brush: php">
&lt;?php
//Catch any errors while testing our script
//Remove when going live.
ini_set(&quot;display_errors&quot;, &quot;1&quot;);
error_reporting(E_ALL); 

//Ensures no one loads page and does simple spam check.
if(isset($_POST[&#039;name&#039;]) &amp;&amp; empty($_POST[&#039;spam_check&#039;]))
{
	//Include our email validator for later use
	require &#039;email-validator.php&#039;;
	$validator = new EmailAddressValidator();

	//Declare our $errors variable we will be using later to store any errors.
	$errors = array();

	//Setup our basic variables
	$input_name = strip_tags($_POST[&#039;name&#039;]);
	$input_email = strip_tags($_POST[&#039;email&#039;]);
	$input_subject = strip_tags($_POST[&#039;subject&#039;]);
	$input_message = strip_tags($_POST[&#039;message&#039;]);

	//We&#039;ll check and see if any of the required fields are empty.
	//We use an array to store the required fields.
	$required = array(&#039;Name field&#039; =&gt; &#039;name&#039;, &#039;Email field&#039; =&gt; &#039;email&#039;, &#039;Message field&#039; =&gt; &#039;message&#039;);

	//Loops through each required $_POST value
	//Checks to ensure it is not empty.
	foreach($required as $key=&gt;$value)
	{
		if(isset($_POST[$value]) &amp;&amp; $_POST[$value] !== &#039;&#039;)
		{
			continue;
		}
		else {
			$errors[] = $key . &#039; cannot be left blank&#039;;
		}
	}

	//Make sure the email is valid.
    if (!$validator-&gt;check_email_address($input_email)) {
           $errors[] = &#039;Email address is invalid.&#039;;
    }

	//Now check to see if there are any errors
	if(empty($errors))
	{

		//No errors, send mail using conditional to ensure it was sent.
		if(mail(&#039;fwdrew@gmail.com&#039;, &quot;Message from $input_name - $input_subject&quot;, $input_message, &quot;From: $input_email&quot;))
		{
			echo &#039;Your email has been sent.&#039;;
		}
		else
		{
			echo &#039;There was a problem sending your email.&#039;;
		}

	}
	else
	{

		//Errors were found, output all errors to the user.
		echo implode(&#039;&lt;br /&gt;&#039;, $errors);

	}
}
else
{
	die(&#039;Direct access to this page is not allowed.&#039;);
}
</pre>
<p>Read through the comments thoroughly, most of the code should explain itself.</p>
<p>A few notes:</p>
<ul>
<li>On lines 4-5, we turn error reporting on, this is always a good idea when testing. Remove these lines before going live.</li>
<li>On line 8, we ensure that no one loads the page directly, but also do a spam check. When spam bots hit a form they usually fill out <em>all</em> HTML input fields, regardless if they are hidden with css or not. Bots also usually fill in every single input field in hopes of successfully submitting the form. We make sure this field is empty before proceeding. This is a small and basic but effective method against some spam.</li>
<li>Lines 11-12 we include and initiate our email validation object.</li>
<li>Lines 29-39 check for any empty fields that are required.</li>
<li>Line 41-43 Check to see if the email is valid</li>
</ul>
<p>The rest should make sense.</p>
<p>Right now you have a complete and working contact form. Congratulations! However, we can make this even easier on the end user by using <a href='http://jquery.com' title='jQuery'>jQuery</a> and a simple AJAX request. jQuery is a Javascript library that allows you to easily do all kinds of cool things, such as <a href='http://dev-tips.com/featured/jquery-tip-quick-and-easy-font-resizing'>quick and easy font resizing</a> and <a href='http://dev-tips.com/featured/jquery-tip-animation-and-css-queuing' title='jQuery Animation'>animation</a>.</p>
<h2>The jQuery/Javascript</h2>
<p>Lets walk through the logic of what we want the jQuery code to do for us, before we start coding it. You'll find this will help you think things through and be more efficient.</p>
<ol>
<li>Include the jQuery library, we've done so in our <code>head</code> section of our HTML already.</li>
<li>When the form is clicked, ensure that we return false.</li>
<li>Setup our necessary variables holding our form values.</li>
<li>Show the user that work is being done (e.g. Loading...).</li>
<li>Make the AJAX request to our contact-send.php file with input fields as POST data.</li>
<li>Grab the response from the php file, and display it under the form, in the response element we have in our HTML page</li>
</ol>
<p>Again, I encourage you to go through each line of the code slowly, and read the comments.</p>
<h3>ajax.js</h3>
<pre class="brush: js">
$(function(){

	//Do what we need to when form is submitted.
	$(&#039;#form_submit&#039;).click(function(){

	//Setup any needed variables.
	var input_name = $(&#039;#form_name&#039;).val(),
		input_email = $(&#039;#form_email&#039;).val(),
		input_subject = $(&#039;#form_subject&#039;).val(),
		input_message = $(&#039;#form_message&#039;).val(),
		response_text = $(&#039;#response&#039;);
		//Hide any previous response text
		response_text.hide();

		//Change response text to &#039;loading...&#039;
		response_text.html(&#039;Loading...&#039;).show();

		//Make AJAX request
		$.post(&#039;http://dev-tips.com/demo/ajax_contact_form/assets/php/contact-send.php&#039;, {name: input_name, email: input_email, subject: input_subject, message: input_message}, function(data){
			response_text.html(data);
		});

		//Cancel default action
		return false;
	});

});
</pre>
<p>Obviously, you will want to change the address/location on line 19 to wherever your file is. The rest should be self explanatory.</p>
<h2>Works Without Javascript!</h2>
<p>Keep in mind a small amount of users wont surf with JavaScript enabled. This means anytime you use AJAX or JavaScript, you need to think about what will happen if JS is disabled. In our case, if JS is disabled, the form will refresh, be validated by php, and send the email if necessary. No worries for us <img src='http://dev-tips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Sit back and relax</h2>
<p>If you've been following along this whole time, you can relax and get some bacon now, you've just built a complete AJAX and PHP contact form from scratch!</p>
<p>Comments? Questions? Suggestions? Let me know what you think in the comments section below. And be sure to check out the live demo and/or download all of the files used in this tutorial.</p>
<div class='box sponsor'>
<h3>Usage</h3>
<p>You <strong>can</strong> use this script in any projects or websites you may have, you just cannot sell it as is. Yes, you can use it in commercial products, you just cannot download the script, and then turn around and sell it. Other than that go crazy!</p>
</div>
<h2 class='box demo'><a target='_blank' href='http://dev-tips.com/demo/ajax_contact_form/index.html' title='Live AJAX Contact Form Demo'>Live Demo</a></h2>
<div class='download_orange'><a class="downloadlink" href="http://dev-tips.com/wp-content/plugins/download-monitor/download.php?id=4" title="Version 1.0 downloaded 1388 times" >Ajax_Contact_Form (1388) - 5.68 KB</a></div>
<h3>I love Chinese food!</h3>
<p>If you found this useful or plan on using this code, will you consider making a donation? I really just want some chicken fried rice.</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="9372484">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"><br />
</form>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/ajax-and-php-contact-form/feed</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>Get Your Recent Delicious Bookmarks Using PHP</title>
		<link>http://dev-tips.com/featured/get-your-recent-delicious-bookmarks-using-php</link>
		<comments>http://dev-tips.com/featured/get-your-recent-delicious-bookmarks-using-php#comments</comments>
		<pubDate>Tue, 27 Oct 2009 01:24:43 +0000</pubDate>
		<dc:creator>Drew Douglass</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=581</guid>
		<description><![CDATA[Salutations and good evening. If any of you are users of the delicious bookmarking system, then you may enjoy a new post we have published on PHP-Tips.net. The post goes through the process of retreiving your lastest bookmarks with php. Visit the post today! Also, don't forget to submit your 404 page to our 3 [...]]]></description>
			<content:encoded><![CDATA[<p>Salutations and good evening. If any of you are users of the delicious bookmarking system, then you may enjoy a new post we have published on <a href='http://php-tips.net' title='PHP Tips'>PHP-Tips.net</a>. The post goes through the process of retreiving your lastest bookmarks with php. <a href='http://php-tips.net/get-delicious-bookmarks-with-php/'>Visit the post today!</a> Also, don't forget to submit your 404 page to our <a href='http://dev-tips.com/featured/wordpress-and-html-theme-giveaway-three-premium-themes-up-for-grabs'>3 theme giveaway contest</a> for your chance to win!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/get-your-recent-delicious-bookmarks-using-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a Relative Time Function</title>
		<link>http://dev-tips.com/featured/creating-a-relative-time-function</link>
		<comments>http://dev-tips.com/featured/creating-a-relative-time-function#comments</comments>
		<pubDate>Mon, 17 Aug 2009 23:07:38 +0000</pubDate>
		<dc:creator>Vasili</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=516</guid>
		<description><![CDATA[You've seen this sort of thing everywhere. It's the new "web 2.0 thing" to do (at least I think so). Instead of displaying the time formatted a certain way no matter how recent it was, you can have "posts about X minutes ago". It gives a new twist to how dates are normally formatted. In [...]]]></description>
			<content:encoded><![CDATA[<p>You've seen this sort of thing everywhere. It's the new "web 2.0 thing" to do (at least I think so). Instead of displaying the time formatted a certain way no matter how recent it was, you can have <em>"posts about X minutes ago"</em>. It gives a new twist to how dates are normally formatted. In this tutorial I will show you how to create a simple PHP function that will accomplish this task for you.</p>
<p><span id="more-516"></span></p>
<div><div id="attachment_521" class="wp-caption alignnone" style="width: 610px"><img src="http://dev-tips.com/wp-content/uploads/2009/08/time_example.jpg" alt="PHP Time Example Image" title="time_example" width="600" height="170" class="size-full wp-image-521" /><p class="wp-caption-text">PHP Time Example Image</p></div></div>
<h3>Information You'll Need To Know</h3>
<p>PHP's dates and times are represented in seconds since January 1, 1970. This means that one minute is represented by 60, hours as 3600 and one day is 86400. No, I don't memorize those, why do you think they made calculators? <img src='http://dev-tips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Try and get familiar with PHP's <a href="http://us3.php.net/manual/en/function.date.php">date function</a> and <a href="http://dev-tips.com/featured/php-quick-tip-using-the-ternary-operator">ternary operators</a>. We'll be using both and they're two things you really should know about.</p>
<h3>Setup the Function</h3>
<p>For the sake of easy recognition I'll be naming the function <strong>relativeTime</strong>. It will accept three parameters: the time to check, the cutoff before the date is formatted, and the format for the date if it meets the limit. The default for the limit is one day which seems pretty fair.</p>
<p>After we have declared the function, we want to set $time to the current time if it's empty or something other than a string or number. However, if it's not empty and a string (like <em>"July 1, 1994 5:30"</em>) then apply <a href="http://us3.php.net/strtotime">strtotime</a> and convert it to something date() can work with. Finally, set a variable to store the current time, and one to hold the return value.</p>
<pre class="brush: php">
&lt;?php
function relativeTime($time = false, $limit = 86400, $format = &#039;g:i A M jS&#039;) {
if (empty($time) || (!is_string($time) &amp;&amp; !is_numeric($time))) $time = time();
elseif (is_string($time)) $time = strtotime($time);

$now = time();
$relative = &#039;&#039;;
}
?&gt;
</pre>
<h3>Is the $time right now?</h3>
<p>The next step is to check weather or not the passed time is the current time. You can change "now" to anything you want, but I thought it would work.</p>
<pre class="brush: php">
if ($time === $now) $relative = &#039;now&#039;;
</pre>
<h3>Or is it in the future?</h3>
<p>Then we'll want to check if the time is in the future. The only time I can see this happening is when you have posts that are scheduled to go up.</p>
<pre class="brush: php">
elseif ($time &gt; $now) $relative = &#039;in the future&#039;;
</pre>
<h3>Nope, it's in the past.</h3>
<p>After the two previous tests have failed, we are positive that the time to check is in the past. It's quite a chunk of code for this last part, but it pretty much repeats itself.</p>
<pre class="brush: php">
else {
$diff = $now - $time;

if ($diff &gt;= $limit) $relative = date($format, $time);
elseif ($diff &lt; 60) {
$relative = &#039;less than one minute ago&#039;;
} elseif (($minutes = ceil($diff/60)) &lt; 60) {
$relative = $minutes.&#039; minute&#039;.(((int)$minutes === 1) ? &#039;&#039; : &#039;s&#039;).&#039; ago&#039;;
} else {
$hours = ceil($diff/3600);
$relative = &#039;about &#039;.$hours.&#039; hour&#039;.(((int)$hours === 1) ? &#039;&#039; : &#039;s&#039;).&#039; ago&#039;;
}
}

return $relative;
</pre>
<p>First we need assign another variable that holds the difference (in seconds) between the date to check and now. If this new variable is greater than or equal to the limit parameter, set $relative to a formatted string. The next elseif statements checks to see if the difference is less than 60 seconds (one minute) and just sends back "less than one minute ago".</p>
<p>We then assign a new variable, $minutes, to the difference divided by 60 and rounded up. If $minutes is less than 60 (one hour), send back "X minute ago". If $minutes is not set to one, an s is appended to minute — this is done with the ternary operator.</p>
<p>The same process is used for the hours, only this time the difference is divided by 3600. Now does it make sense why I told you you will need to know that? <img src='http://dev-tips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>We finish the function by returning $realtive, which now contains one of six options.</p>
<h3>Conclusion</h3>
<pre class="brush: php">
&lt;?php
function relativeTime($time = false, $limit = 86400, $format = &#039;g:i A M jS&#039;) {
if (empty($time) || (!is_string($time) &amp;amp;&amp;amp; !is_numeric($time))) $time = time();
elseif (is_string($time)) $time = strtotime($time);

$now = time();
$relative = &#039;&#039;;

if ($time === $now) $relative = &#039;now&#039;;
elseif ($time &gt; $now) $relative = &#039;in the future&#039;;
else {
$diff = $now - $time;

if ($diff &gt;= $limit) $relative = date($format, $time);
elseif ($diff &lt; 60) {
$relative = &#039;less than one minute ago&#039;;
} elseif (($minutes = ceil($diff/60)) &lt; 60) {
$relative = $minutes.&#039; minute&#039;.(((int)$minutes === 1) ? &#039;&#039; : &#039;s&#039;).&#039; ago&#039;;
} else {
$hours = ceil($diff/3600);
$relative = &#039;about &#039;.$hours.&#039; hour&#039;.(((int)$hours === 1) ? &#039;&#039; : &#039;s&#039;).&#039; ago&#039;;
}
}

return $relative;
}
?&gt;
</pre>
<p>This may seem like a simple function but it's very helpful. I recently coded up a quick Twitter widget for my friend (because I told her the default one was crap...) and she wanted to have the dates in relative time. I was lucky to have already had this function saved on my computer. Hope you enjoyed and learned something new!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/creating-a-relative-time-function/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>5 More Quality Sites to Help You Become a PHP Rockstar</title>
		<link>http://dev-tips.com/featured/5-more-quality-sites-to-help-you-become-a-php-rockstar</link>
		<comments>http://dev-tips.com/featured/5-more-quality-sites-to-help-you-become-a-php-rockstar#comments</comments>
		<pubDate>Wed, 15 Jul 2009 21:58:24 +0000</pubDate>
		<dc:creator>Drew Douglass</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=486</guid>
		<description><![CDATA[Not too long ago, we posted a popular article titled 5 quality sites to increase your knowledge of php. We received quite a positive response from this article and a few emails asking for more. That's all we needed to hear! Today we are back, and will be going over 5 more quality websites to [...]]]></description>
			<content:encoded><![CDATA[<p>Not too long ago, we posted a popular article titled <a href='http://dev-tips.com/featured/5-quality-sites-to-increase-your-knowledge-of-php' title='5 quality sites to increase your knowledge of php'>5 quality sites to increase your knowledge of php</a>. We received quite a positive response from this article and a few emails asking for more. That's all we needed to hear! Today we are back, and will be going over 5 more quality websites to help you become a php rockstar.</p>
<p><span id="more-486"></span></p>
<h2>0. phpro.org</h2>
<div class='tut_image'><a href='http://phpro.org'><img src='http://dev-tips.com/post_img/phpro.jpg' alt='PHPRO.org' /></a></div>
<p>I'm really surprised that I completely forgot to mention this site in our first php roundup. Though it takes a while for the author to publish a new post, the post quality found at <a href='http://phpro.org'>phpro.org</a> is second to none. These are hands down the most in depth, well explained, and well thought out articles on php I have read in a long time.</p>
<h2>1. PHP Developer</h2>
<div class='tut_image'><a href='http://phpdeveloper.org/' title='PHP Developer'><img src='http://dev-tips.com/post_img/php_developer.jpg' alt='PHP Developer' /></a></div>
<p><a href='http://phpdeveloper.org/'>PHP Developer</a> is your one stop shop for any php news, articles or tutorials. Many of the articles focus on advanced programming topics as well as new php releases, bug fixes, and different classes. If you are wanting to immerse yourself in the world of php, go ahead and subscribe to PHP Developer.</p>
<h2>2. Cal Evans Blog</h2>
<div class='tut_image'><a href='http://blog.calevans.com/' title='Cal Evans'><img src='http://dev-tips.com/post_img/cal_evans.jpg' alt='Cal Evans Blog' /></a></div>
<p>With a tagline of "Lint I find in my mind’s belly-button" it's hard not to like <a href='http://blog.calevans.com'>Cal Evans</a>. Cal is currently an independent computer consultant with a giant <a href='http://blog.calevans.com/resume-of-cal-evans/'>resume to back it up</a>. Cal has a lot of experience with Zend and php, as well as all kinds of different languages. His blog is always full of humour and interesting insights. I highly encourage you to check out the posts Cal has to offer.</p>
<h2>3. Derek Allard</h2>
<div class='tut_image'><a href='http://derekallard.com/'><img src='http://dev-tips.com/post_img/derek_allard.jpg' alt='Derek Allard' /></a></div>
<p><a href='http://derekallard.com/'>Derek Allard</a> is a programmer and one of the creators of the very popular php framework, <a href='http://codeigniter.com'>CodeIgniter</a>. Derek works at Ellis labs, whom have created such popular apps such as Bamboo Invoice. Derek frequently covers topics on php and the CodeIgniter framework, excellent for those who are jumping into the MVC style of php.</p>
<h2>4. David Walsh</h2>
<div class='tut_image'><a href='http://davidwalsh.name' title='David Walshs Blog'><img src='http://dev-tips.com/post_img/david_walsh.jpg' alt='David Walsh' /></a></div>
<p>Most of you are probably familiar with <a href='http://davidwalsh.name'>David Walsh</a> or his work. David is a fantastic web developer and in particularly, a Javascript guru. Even though a lot of his articles are on the topic of JS, many of them tend to incorporate the use of php, such as some nice AJAX techniques. David also has some very nice php classes and methods he has written over the years. If you are not reading Davids' blog, I highly encourage you to do so, David is as quality as developers come.</p>
<p>That'll do it for now, have I missed any sites that you all frequent for php help? What are some of your favorites? Let me know and I might include them in the next php roundup!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/5-more-quality-sites-to-help-you-become-a-php-rockstar/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Introducing the Ultimate Gallery Management System!</title>
		<link>http://dev-tips.com/featured/introducing-the-ultimate-gallery-management-system</link>
		<comments>http://dev-tips.com/featured/introducing-the-ultimate-gallery-management-system#comments</comments>
		<pubDate>Wed, 17 Jun 2009 08:25:44 +0000</pubDate>
		<dc:creator>Drew Douglass</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=460</guid>
		<description><![CDATA[If you've been following me on twitter, you may know that I have been working on a big project for ThemeForest recently. Today, I am proud to announce that months of hard work have paid off as the component has officially launched with version 1.1 today! I'd like to show off the system and discuss [...]]]></description>
			<content:encoded><![CDATA[<p>If you've been <a href='http://twitter.com/drewdouglass'>following me</a> on twitter, you may know that I have been working on a <em>big</em> project for <a href='http://themeforest.net/?ref=CreatingDrew'>ThemeForest</a> recently. Today, I am proud to announce that months of hard work have paid off as <a href='http://themeforest.net/item/the-ultimate-image-gallery-manager/46388?ref=CreatingDrew'>the component</a> has officially launched with <a href='http://themeforest.net/item/the-ultimate-image-gallery-manager/46388?ref=CreatingDrew'>version 1.1</a> today! I'd like to show off the system and discuss exactly what it does, so you can have a better idea.</p>
<p><span id="more-460"></span></p>
<h2 class='box demo'><a href='http://themeforest.net/item/the-ultimate-image-gallery-manager/46388?ref=CreatingDrew'>Visit Ultimate Gallery Homepage</a></h2>
<h2>What the heck is it?</h2>
<p>In short, think of the <a href='http://themeforest.net/item/the-ultimate-image-gallery-manager/46388?ref=CreatingDrew' title='Ultimate Image Gallery Management System'>Ultimate Gallery</a> as WordPress for image galleries. You install the system on your own server, and you create thousands of image galleries with thousands (or millions) of photos. There are all kinds of features packed into the galleries that are created for you, such as custom user defined pagination, lightbox effects, slideshows, and a ton more. I can't explain it all in one paragraph, check out some of the features and screenshots below!</p>
<h2>Features Include:</h2>
<ul>
<li>Create and manage thousands of different image galleries.</li>
<li>Powerful resizing and photo editing options such as grayscale conversion and sketch effect!</li>
<li>Custom pagination for each gallery, you choose how many show per page and edit it whenever you want!</li>
<li>All types of transparency supported!</li>
<li>Super easy install on your own server gives you full control, no more hosting images by relying on a third party!</li>
<li>Style your galleries however you like depending on your taste.</li>
<li>Ability to handle multiple users.</li>
<li>SEO friendly gallery urls make it easy to share your gallery with the world.</li>
<li>Even when photos are resized for a gallery (based on your resize preference) a full size is kept available for the 'lightbox' technique.</li>
<li>Plenty of gallery options and settings, including max thumbnail sizes for a certain gallery, you can change this max size at any time without losing resolution!</li>
<li>Fun image editing options such as 'Convert to GrayScale' and 'Sketch Effect'. </li>
<li>Sleek 'lightbox' effect automatically on all image galleries created.</li>
<li>Slideshow effect integrates smoothly with lightbox effect if desired.</li>
<li>Convenient user features such as lost/change password, page loading times, last login etc.</li>
<li>Extremely customizable and easy to install.</li>
<li>Built on CodeIgniter, speed and security are excellent.</li>
<li>Of course the entire .psd for the admin area comes with the download, do with it what you like!</li>
<li>So much more, I can't fit it all in here, just check out the online user guide and demo!</li>
</ul>
<h2>Screenshots</h2>
<p>Login Page:</p>
<div><img src='http://dev-tips.com/post_img/1_Login.jpg' alt='Login Page' /></div>
<p>Admin Home Page:</p>
<div><img src='http://dev-tips.com/post_img/2_Admin_Home.jpg' alt='Admin Home' /></div>
<p>Add Gallery Page:</p>
<div><img src='http://dev-tips.com/post_img/3_Add_Gallery.jpg' alt='Add Gallery' /></div>
<p>Edit Galleries List:</p>
<div><img src='http://dev-tips.com/post_img/4_Edit_Galleries.jpg' alt='Edit Galleries' /></div>
<p>Edit Individual Gallery:</p>
<div><img src='http://dev-tips.com/post_img/5_Edit_Gallery.jpg' alt='Edit Gallery' /></div>
<p>Image Upload Success:</p>
<div><img src='http://dev-tips.com/post_img/6_Image_Success.jpg' alt='Image Upload' /></div>
<p>Edit Individual Image Mode:</p>
<div><img src='http://dev-tips.com/post_img/8_Edit_Image.jpg' alt='Edit Image' /></div>
<p>Edit Lightbox Effect (admin panel):</p>
<div><img src='http://dev-tips.com/post_img/9_Edit_Lightbox.jpg' alt='Edit Lightbox' /></div>
<p>Register New User:</p>
<div><img src='http://dev-tips.com/post_img/10_Register_User.jpg' alt='Register User' /></div>
<p>Unstyled Gallery With Custom Pagination:</p>
<div><img src='http://dev-tips.com/post_img/12_Flower_Gallery.jpg' alt='Unstyled Gallery' /></div>
<p>Unstyled Gallery Lightbox Effect</p>
<div><img src='http://dev-tips.com/post_img/13_Gallery_Lightbox.jpg' alt='Lightbox Gallery' /></div>
<h2>Tell me more!</h2>
<p>The <a href='http://themeforest.net/item/the-ultimate-image-gallery-manager/46388?ref=CreatingDrew'>Ultimate Gallery</a> is built on <a href='http://codeigniter.com'>CodeIgniter</a>, which is my framework of choice. It utilizes the <a href='http://jquery.com/'>jQuery</a> javascript library, and will soon include the <a href='http://flowplayer.org/tools/demos/index.html'>jQuery tools</a> library as well.</p>
<p>There are all kinds of features and special little functions to check out. Just take a look at the <a href='http://themeforest.net/item/the-ultimate-image-gallery-manager/46388?ref=CreatingDrew'>Ultimate Gallery Management System</a> homepage and see for yourself!</p>
<h2 class='box demo'><a href='http://themeforest.net/item/the-ultimate-image-gallery-manager/46388?ref=CreatingDrew'>Visit Ultimate Gallery Homepage</a></h2>
<h2 class='box demo'><a href='http://ultimategallery.dev-tips.com'>Visit the Demo and Online Documentation</a></h2>
<p>I would really appreciate it if you all would give it a look, check out the demo, and let me know what you think. I'd love to here from my fellow developers!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/introducing-the-ultimate-gallery-management-system/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How To Use Custom ini Files With PHP</title>
		<link>http://dev-tips.com/featured/how-to-use-custom-ini-files-with-php</link>
		<comments>http://dev-tips.com/featured/how-to-use-custom-ini-files-with-php#comments</comments>
		<pubDate>Thu, 04 Jun 2009 02:18:48 +0000</pubDate>
		<dc:creator>Drew Douglass</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=448</guid>
		<description><![CDATA[The special 'config' file is a very important file at the heart of almost every web/software application. The config file typically holds information that will be used over and over again, such as database info. There are plenty of ways you can go about creating a config file. Many just create a new file with [...]]]></description>
			<content:encoded><![CDATA[<p>The special 'config' file is a very important file at the heart of almost every web/software application. The config file typically holds information that will be used over and over again, such as database info. There are plenty of ways you can go about creating a config file. Many just create a new file with some defined constants and include the file. Others use a database or XML file for config storage. Today, we will have a look at a simple example of using a custom ini file to set our preferences.</p>
<p><span id="more-448"></span></p>
<h2>The config.ini file</h2>
<p>Setting up a config.ini file is super simple. Create a new file on your server named 'config.ini' and type in something like below:</p>
<pre class="brush: php">
;This is a basic ini file setup
;
;Note how comments are made with semi colons?

[version_info]
version_number = 3.0
version_stable = true
last_updated = 06/23/08

[db_info]
db_name = MyDatabase
db_user = root
db_pass = root
</pre>
<h2>The PHP file</h2>
<p>Now all we need to do is parse the contents of the file, we can do this using the <a href='http://us2.php.net/manual/en/function.parse-ini-file.php' title='Parse ini function'>parse_ini_file()</a> function.</p>
<pre class="brush: php">
&lt;?php
ini_set(&quot;display_errors&quot;, &quot;1&quot;);
error_reporting(E_ALL); 

//Parse and store the ini file, this will return an associative array
$config_info = parse_ini_file(&#039;config.ini&#039;, true);

//Debug
print_r($config_info);

//Example usage
echo &#039;You are currently running version &#039; . $config_info[&#039;version_info&#039;][&#039;version_number&#039;];
?&gt;
</pre>
<p>This would output <code>You are currently running version 3.0 </code></p>
<h2>Other options</h2>
<p>As I said, this is just one way to store important configuration data. A few other options include, but are not limited to:</p>
<ul>
<li>XML File</li>
<li>PHP File</li>
<li>Database Storage (obviously where applicable)</li>
</ul>
<p>Simple right? Obviously, this is a super simplified example, but you can see how easy and helpful a basic .ini file can be! What are some of your methods for storing config preferences?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/how-to-use-custom-ini-files-with-php/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Remove an Item From an Array By Value</title>
		<link>http://dev-tips.com/featured/remove-an-item-from-an-array-by-value</link>
		<comments>http://dev-tips.com/featured/remove-an-item-from-an-array-by-value#comments</comments>
		<pubDate>Sun, 10 May 2009 00:34:08 +0000</pubDate>
		<dc:creator>Vasili</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=436</guid>
		<description><![CDATA[I was working on my CMS a couple days ago when I was trying to remove an item from an array by value. I tried to find a function already built into PHP but couldn't. I developed this little function to do this simple task for me. How am I going to call this function? [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on my CMS a couple days ago when I was trying to remove an item from an array by value. I tried to find a function already built into PHP but couldn't. I developed this little function to do this simple task for me.</p>
<p><span id="more-436"></span></p>
<h3>How am I going to call this function?</h3>
<p>I sometimes like to imagine how I'm going to call this function before I actually write it. I decided that having three parameters would be just fine for my situation; the third parameter, $preserve_keys, could be removed and this function would still work just like it should.</p>
<pre class="brush: php">
&lt;?php
$myArray = array(&#039;item1&#039;, &#039;item2&#039;, &#039;item3&#039; ...);
$removeThis = &#039;item2&#039;;

$newArray = remove_item_by_value($removeThis, $removeThis);
?&gt;
</pre>
<h3>Breaking it down one line at a time</h3>
<p>Instead of writing one line at a time, I thought it would be better to give you the code then explain each one of the lines individually.</p>
<pre class="brush: php">
&lt;?php
function remove_item_by_value($array, $val = &#039;&#039;, $preserve_keys = true) {
	if (empty($array) || !is_array($array)) return false;
	if (!in_array($val, $array)) return $array;

	foreach($array as $key =&gt; $value) {
		if ($value == $val) unset($array[$key]);
	}

	return ($preserve_keys === true) ? $array : array_values($array);
}
?&gt;
</pre>
<ol>
<li><strong>Lines 1-2:</strong> We begin by opening up PHP and declaring the function. Three parameters are allowed to be passed into this function: the array we want to remove items from; the value we're looking for when we remove items; and finally if the function should preserve the keys of the stripped array (this is helpful for associate arrays).</li>
<li><strong>Lines 3-4:</strong> Some basic checking goes on before we loop through the array. The function will return false if the array is empty or it isn't even an array at all. Also, I added at the last minute a check to see if this value even exists in the array. There would be no point in wasting server time looping through an array looking for something that isn't even there.</li>
<li><strong>Lines 6-8:</strong> We use a <a href="http://us3.php.net/manual/en/control-structures.foreach.php">foreach</a> loop to check each value and see if it matches up with the value passed. If there is a match, the function <a href="http://us.php.net/unset">unsets</a> that specific item. <em>PHP tip: To select the current item in a foreach loop make sure you assign the key to a variable then get it with a similar syntax to $array[$key].</em></li>
<li><strong>Line 10:</strong> We use a <a href="http://dev-tips.com/featured/php-quick-tip-using-the-ternary-operator">ternary operator</a> to return the array with its keys intact or with new keys. An easy way to return only the values of an array is using <a href="http://us3.php.net/array_values">array_values</a>.</li>
<li><strong>Lines 11-12:</strong> We close the function and PHP and call this function done!</li>
</ol>
<h3>Conclusion</h3>
<p>As you can see, this function is very simple but can save you loads of time down the road. However, I can already see a problem with this. It doesn't accommodate multi-demensional arrays. Don't be afraid to build off this function and have it work with multi-dementional arrays, I would love to see what you would do to solve that!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/remove-an-item-from-an-array-by-value/feed</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>How to Validate Age With PHP</title>
		<link>http://dev-tips.com/featured/how-to-validate-age-with-php</link>
		<comments>http://dev-tips.com/featured/how-to-validate-age-with-php#comments</comments>
		<pubDate>Sun, 03 May 2009 19:00:44 +0000</pubDate>
		<dc:creator>Drew Douglass</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Side]]></category>

		<guid isPermaLink="false">http://dev-tips.com/?p=388</guid>
		<description><![CDATA[I was recently browsing the analytic statistics and information for Dev-Tips when I noticed that a common search was appearing on the site. The search terms were how to validate age with php. I immediately saw this as an opportunity to provide an answer to a very simple php question, as it is quite simple [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently browsing the analytic statistics and information for <a href='http://dev-tips.com'>Dev-Tips</a> when I noticed that a common search was appearing on the site. The search terms were <strong>how to validate age with php</strong>. I immediately saw this as an opportunity to provide an answer to a very simple php question, as it is quite simple to validate an age with php. Let's have a quick look and write a script that will allow us to validate that a user is a certain age with php.</p>
<p><span id="more-388"></span></p>
<p>First, let me say that there are <strong>a lot</strong> of different ways that we could do this, we could spend weeks writing different ways on how to accomplish this best. Disclaimer aside, let's look at a simple and procedural option.</p>
<pre class="brush: php">
&lt;?php
//users birthday, ideally you would take this data from a form
$user_bd = strtotime(&#039;March 14, 1997&#039;);

//Age requirement, using 21 as the minimum age required
$age_req = strtotime(&#039;+21 years&#039;, $user_bd);

//Grab the current UNIX timestamp and compare it to the minimum required
if(time() &lt; $age_req){
	echo &#039;Not 21 years or older.&#039;;
}
else{
	echo &#039;Word. Come on in.&#039;;
}
?&gt;
</pre>
<p>Our script goes through the following steps:</p>
<ol>
<li>Parse the users birthday as a UNIX timestamp using <a href='http://us2.php.net/strtotime/'>strtotime()</a> and store the result in a variable. Ideally this info would come from a form/select box on your page.</li>
<li>Determine the minimum age they need to be. We will use 21 years old. We add 21 years to our original date, parse it as a UNIX timestamp, and store it in a variable.</li>
<li>If the current timestamp is less than the age required, print to the screen or do whatever you wish with the user (re-direct, exit() etc.). Else, the user is old enough.</li>
</ol>
<p>And that is one way you can validate any age with php. Hopefully, the users coming to this site will now find it more helpful that we have posted the answer to the common search query. Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tips.com/featured/how-to-validate-age-with-php/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
