<?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 &#187; PHP</title>
	<atom:link href="http://www.ericditmer.com/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ericditmer.com</link>
	<description>ericditmer.com</description>
	<lastBuildDate>Tue, 08 Nov 2011 14:35:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>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>Tue, 20 Sep 2011 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 [...]]]></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>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>Thu, 08 Sep 2011 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>
	</channel>
</rss>

