<?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>Eric Ditmer</title>
	<atom:link href="http://www.ericditmer.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ericditmer.com</link>
	<description>ericditmer.com</description>
	<lastBuildDate>Tue, 13 Apr 2010 04:48:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Top 5 PHP Regular Expressions for Web Developers</title>
		<link>http://www.ericditmer.com/top-5-php-regular-expressions</link>
		<comments>http://www.ericditmer.com/top-5-php-regular-expressions#comments</comments>
		<pubDate>Mon, 12 Apr 2010 07:19:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ericditmer.com/?p=65</guid>
		<description><![CDATA[There&#8217;s no doubt about it, regular expressions are flippin&#8217; awesome. Here, I&#8217;ve compiled a list of five user-defined PHP functions that I use regularly when developing back-end applications. All of these functions make use of regular expression matching.

1.) Return Alphanumeric Only
A very handy regular expression that I like to use for cleaning up usernames. It [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s no doubt about it, regular expressions are flippin&#8217; awesome. Here, I&#8217;ve compiled a list of five user-defined PHP functions that I use regularly when developing back-end applications. All of these functions make use of regular expression matching.<br />
<span id="more-65"></span></p>
<h3>1.) Return Alphanumeric Only</h3>
<p>A very handy regular expression that I like to use for cleaning up usernames. It takes a string and returns its alphanumeric equivalency:</p>
<pre name="code" class="php">
&lt;?php
function alphaNumeric($string) {
	return preg_replace("/[^a-zA-Z0-9]/", "", $string);
}
?&gt;</pre>
<p><b>Sample string:</b> DanMarino#13!@#$<br />
<b>Returns:</b> DanMarino13</p>
<h3>2.) Validate Email Address</h3>
<p>This regular expression will return true if the string passed is a valid email address:</p>
<pre name="code" class="php">&lt;?php
function checkEmail($email) {
	return preg_match("/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i", $email);
}
?&gt;</pre>
<p><b>Sample string:</b> test@example.com<br />
<b>Returns:</b> 1 (true)</p>
<h3>3.) Check for Valid URL</h3>
<p>A nifty regular expression that will return true if the given string is a valid URL:</p>
<pre name="code" class="php">&lt;?php
function checkURL($url) {
	return preg_match("/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&amp;?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/", $url);
}
?&gt;</pre>
<p><b>Sample string:</b> http://www.google.com<br />
<b>Returns:</b> 1 (true)</p>
<h3>4.) Check for Valid Hex Code</h3>
<p>I often use this regular expression when developing sites that allow users to customize themes with hex codes. It will return true if a valid hex code is provided:</p>
<pre name="code" class="php">&lt;?php
function checkHexCode($hex_code) {
	return preg_match("/^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$/", $hex_code);
}
?&gt;</pre>
<p><b>Sample string:</b> FF0000<br />
<b>Returns:</b> 1 (true)</p>
<h3>5.) Text Snippet, No Cut-Off In Middle of Word</h3>
<p>Easily one of my favorite functions. This regular expression accepts a string and a character limit, and returns a shortened string without cutting off the middle of a word:</p>
<pre name="code" class="php">&lt;?php
function textSnippet($str, $num) {
	$string_match = preg_match("/^([\s\S]){1," . $num . "}([\s\.])/",  $str, $matches);
	$shortened_string = $matches[0];
	return $shortened_string . '...';
}
?&gt;</pre>
<p><b>Sample string:</b> Look at this crazy long line of text.<br />
<b>Returns:</b> Look at this crazy&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ericditmer.com/top-5-php-regular-expressions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set Elements to Equal Heights with jQuery</title>
		<link>http://www.ericditmer.com/equal-heights-jquery</link>
		<comments>http://www.ericditmer.com/equal-heights-jquery#comments</comments>
		<pubDate>Sun, 11 Apr 2010 06:01:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.ericditmer.com/?p=58</guid>
		<description><![CDATA[Here&#8217;s a quick jQuery plugin I put together for equalizing the heights of multiple elements. You give the plugin a list of elements, jQuery then loops through the specified elements, finds the tallest, and sets the height of each element to the tallest one.


(function ($) {
	$.fn.equalHeights = function() {
		var max_height = 0;
		var currentHeight = 0;

		this.each(function() [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick jQuery plugin I put together for equalizing the heights of multiple elements. You give the plugin a list of elements, jQuery then loops through the specified elements, finds the tallest, and sets the height of each element to the tallest one.</p>
<p><span id="more-58"></span></p>
<pre name="code" class="javascript">
(function ($) {
	$.fn.equalHeights = function() {
		var max_height = 0;
		var currentHeight = 0;

		this.each(function() {
			currentHeight = $(this).height();
			if(currentHeight > max_height) {
				max_height = currentHeight;
			}
		});
		this.each(function() {
			$(this).height(max_height);
		});
	};
})(jQuery);
</pre>
<h3>Usage</h3>
<p>It&#8217;s pretty simple, all you have to do is give the plugin a list of elements like so:</p>
<pre name="code" class="javascript">
$(document).ready(function() {
    $("#div-one, #div-two, #div-three").equalHeights();
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ericditmer.com/equal-heights-jquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find and Replace with MySQL</title>
		<link>http://www.ericditmer.com/find-and-replace-with-mysql</link>
		<comments>http://www.ericditmer.com/find-and-replace-with-mysql#comments</comments>
		<pubDate>Sun, 11 Apr 2010 04:24:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ericditmer.com/?p=132</guid>
		<description><![CDATA[A long long time ago, when dinosaurs roamed the earth, I had a client that had written all of her pages&#8217; text in Microsoft Word, and pasted them directly into her content management system. This resulted in over 50 pages of content that would display nasty characters in some browsers. Back then, I went through [...]]]></description>
			<content:encoded><![CDATA[<p>A long long time ago, when dinosaurs roamed the earth, I had a client that had written all of her pages&#8217; text in Microsoft Word, and pasted them directly into her content management system. This resulted in over 50 pages of content that would display nasty characters in some browsers. <span id="more-132"></span>Back then, I went through each and every page and replaced those nasty characters with their cross-browser alternatives. Nowadays, I&#8217;d use a schmexy MySQL query like the one below:</p>
<pre name="code" class="php">
&lt;?php
$find_and_replace_query = mysql_query("UPDATE `table` SET `field` =
REPLACE(`field`, 'string_to_find', 'string_to_replace')");
?>
</pre>
<p>That&#8217;s it, you ask? Yep! Sure beats the grueling process of updating 50 pages one at a time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ericditmer.com/find-and-replace-with-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started With mod_rewrite</title>
		<link>http://www.ericditmer.com/getting-started-with-mod-rewrite</link>
		<comments>http://www.ericditmer.com/getting-started-with-mod-rewrite#comments</comments>
		<pubDate>Sun, 11 Apr 2010 01:29:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.htaccess]]></category>

		<guid isPermaLink="false">http://www.ericditmer.com/?p=86</guid>
		<description><![CDATA[What is mod_rewrite?
First of all, let&#8217;s get things straight: mod_rewrite is your friend. It is also an Apache module that rewrites URL&#8217;s at the server level. If you&#8217;re reading this, I&#8217;m going to assume you&#8217;ve already enabled mod_rewrite on your server. If not, there&#8217;s plenty of tutorials to show you how to enable it. All [...]]]></description>
			<content:encoded><![CDATA[<h3>What is mod_rewrite?</h3>
<p>First of all, let&#8217;s get things straight: <b>mod_rewrite is your friend</b>. It is also an Apache module that rewrites URL&#8217;s at the server level. If you&#8217;re reading this, I&#8217;m going to assume you&#8217;ve already enabled mod_rewrite on your server. If not, there&#8217;s plenty of <a href="http://www.tutorio.com/tutorial/enable-mod-rewrite-on-apache" target="_blank">tutorials</a> to show you how to enable it. All set? Okay, let&#8217;s go!<br />
<span id="more-86"></span></p>
<h3>Simple mod_rewrite Example</h3>
<p>We&#8217;ll be starting with a simple mod_rewrite example just to get your feet wet. All rewrite rules follow a particular structure: <i>RewriteRule Pattern Substitution [OptionalFlags]</i><br />This example will redirect <u>http://www.example.com/foo.html</u> to <u>http://www.example.com/bar.html</u>. This can be accomplished by creating an .htaccess file and inserting the following:</p>
<pre name="code" class="html">
&lt;?php
RewriteEngine on
RewriteRule ^foo.html$ bar.html
?>
</pre>
<p>Visiting <u>http://www.example.com/foo.html</u> will now redirect you to <u>http://www.example.com/bar.html</u>. However, notice that the URL still displays <u>foo.html</u>. If you&#8217;d prefer the browser to visibly redirect to the new page, you&#8217;ll need to make a couple changes to your .htaccess file:</p>
<pre name="code" class="html">
&lt;?php
RewriteEngine on
RewriteRule ^foo.html$ http://www.example.com/bar.html [R]
?>
</pre>
<p>You&#8217;ll notice that I&#8217;ve added an [R] flag to the end of the rewrite rule. This tells the browser to visibly redirect to the new page. Also, I had to write out the full URL of the page that I&#8217;m redirecting to. If the page you&#8217;re redirecting to happens to fall within the root directory of the same site, you can simply write <u>/page.html</u> instead of the full URL.</p>
<h3>Fancy Schmancy Redirect</h3>
<p>This example is going to show you how to make your URL&#8217;s pretty. I&#8217;m talking prettier than Halle Berry. Let&#8217;s start off with an example:</p>
<pre name="code" class="html">
&lt;?php
RewriteEngine On
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?category=$1&#038;product=$2 [L]
?>
</pre>
<p>With a rewrite rule like this in place, <u>http://www.example.com/nestle/quik</u> effectively redirects to <u>http://www.example.com/index.php?category=nestle&#038;product=quik</u>. I&#8217;m going to break this rewrite rule out into multiple parts, seeing how it&#8217;s a bit more complicated than the first example:</p>
<ol>
<li><b><u>^([^/\.]+)/([^/\.]+)/?$</u></b> &#8211; This pattern returns two variables, separated by a forward-slash. The two variables can contain any characters that aren&#8217;t a forward-slash or a period.</li>
<li><b><u>$1.php</u></b> &#8211; This is the page that you&#8217;ll be redirected to. $1 and $2 will be replaced with the previously captured data, respectively.</li>
<li><b><u>[L]</u></b> &#8211; This optional flag tells Apache to stop processing rewrite rules after this point.</li>
</ol>
<p>Well, I hope this wasn&#8217;t too overwhelming. This is just scratching the surface of mod_rewrite. Remember though, once you&#8217;ve got mod_rewrite down, all the ladies will constantly swarm you. Okay, that might not be true, but it will definitely save you a few headaches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ericditmer.com/getting-started-with-mod-rewrite/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Center an Element Horizontally and Vertically</title>
		<link>http://www.ericditmer.com/center-element-horizontally-vertically</link>
		<comments>http://www.ericditmer.com/center-element-horizontally-vertically#comments</comments>
		<pubDate>Fri, 09 Apr 2010 04:49:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.ericditmer.com/?p=202</guid>
		<description><![CDATA[This one is an oldie but a goody. Using basic HTML/CSS we can position an element directly in the center of the page. Here are the steps to perfectly centering an element:

Absolutely position the element
Position the element 50% from the top, 50% from the left
Define the width/height of the element you wish to center
Compensate for [...]]]></description>
			<content:encoded><![CDATA[<p>This one is an oldie but a goody. Using basic HTML/CSS we can position an element directly in the center of the page. Here are the steps to perfectly centering an element:<span id="more-202"></span></p>
<ol>
<li>Absolutely position the element</li>
<li>Position the element 50% from the top, 50% from the left</li>
<li>Define the width/height of the element you wish to center</li>
<li>Compensate for the image&#8217;s width and height by applying two negative margins: A negative left margin set to half of the image&#8217;s width, and a negative top margin set to half of the image&#8217;s height.</li>
</ol>
<pre name="code" class="css">
#center-me {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 600px;
	height: 260px;
	margin-left: -300px;
	margin-top: -130px;
	background: url('../images/holy-crap-centered.gif') no-repeat;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ericditmer.com/center-element-horizontally-vertically/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making AJAX Requests with jQuery</title>
		<link>http://www.ericditmer.com/ajax-requests-with-jquery</link>
		<comments>http://www.ericditmer.com/ajax-requests-with-jquery#comments</comments>
		<pubDate>Thu, 08 Apr 2010 04:11:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.ericditmer.com/?p=194</guid>
		<description><![CDATA[Making an XMLHttpRequest (AJAX request) enables JavaScript code to make asynchronous HTTP requests to the server. Creating the XMLHttpRequest object via standard JavaScript quickly turns into a lengthy bit of code. This is where JavaScript&#8217;s beautiful cousin steps in: jQuery. 
jQuery Makes Writing JavaScript Easier
With jQuery, we can create our XMLHttpRequest in just under 10 [...]]]></description>
			<content:encoded><![CDATA[<p>Making an XMLHttpRequest (AJAX request) enables JavaScript code to make asynchronous HTTP requests to the server. Creating the XMLHttpRequest object via standard JavaScript quickly turns into a lengthy bit of code. This is where JavaScript&#8217;s beautiful cousin steps in: jQuery. <span id="more-194"></span></p>
<h3>jQuery Makes Writing JavaScript Easier</h3>
<p>With jQuery, we can create our XMLHttpRequest in just under 10 lines of code:</p>
<pre name="code" class="js">
$.ajax({
    var rand = Math.round(Math.random() * 999999);
    type: "POST",
    url: "ajax-page.php",
    data: "name=Eric&#038;location=Ohio&#038;rand=" + rand,
    success: function(msg) {
        alert(msg);
    }
});
</pre>
<h3>Stupid Internet Explorer</h3>
<p>If you&#8217;re using the GET method when submitting via AJAX, Internet Explorer may try to cache your request. We have solved this issue by adding a random number to the end of our query string as referenced in the example above.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ericditmer.com/ajax-requests-with-jquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
