<?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>Eddie On Everything &#187; PHP</title>
	<atom:link href="http://www.eddieoneverything.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.eddieoneverything.com</link>
	<description>Tips &#38; tricks on things that interest me</description>
	<lastBuildDate>Wed, 11 Jan 2012 08:29:23 +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>Validating an Email Address with PHP&#8217;s filter_var isn&#8217;t perfect</title>
		<link>http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php</link>
		<comments>http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php#comments</comments>
		<pubDate>Wed, 11 May 2011 23:53:20 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[email addresses]]></category>
		<category><![CDATA[email validation]]></category>
		<category><![CDATA[filter_var]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php</guid>
		<description><![CDATA[So I’m working on a project where I need to validate that the user has entered a correct email address.
I don’t really care if someone sticks in a “fake” email address – to complete registration, the user needs to enter a confirmation code that I send via email, so if they put in a fake [...]]]></description>
			<content:encoded><![CDATA[<p>So I’m working on a project where I need to validate that the user has entered a correct email address.</p>
<p>I don’t really care if someone sticks in a “fake” email address – to complete registration, the user needs to enter a confirmation code that I send via email, so if they put in a fake address, they never complete registration, and the aborted account signup is eventually purged anyway.  No sweat off my back.</p>
<p>But I do want to catch those few cases where the user makes a legitimate mistake, like mistakenly entering just their name into the email address field.  (Don’t laugh, it happens more often than you’d think.)</p>
<p>One of the biggest mistakes users make when filling out these forms is that they omit the TLD (that&#8217;s &#8220;Top-Level-Domain,&#8221; like .com, or .edu) from the email address.  I assume that it’s mostly new computer users who do this, and I’ve seen it happen often enough that I’m sure these folks just don’t know any better.  So unsophisticated user “billg@microsoft.com” might mistakenly enter only “billg@microsoft”, thinking he did everything correctly.  Then he sits waiting for a confirmation email that never arrives.</p>
<p>I don’t really like <a href="http://www.linuxjournal.com/article/9585" target="_blank">fancy</a> email address validation techniques.  They seem so unnecessary.  Programmers like to get all caught up in writing the perfect regular expression that “catches” all cases, and not only is it a complete mess to maintain, but it’s easily circumvented by the end user who types in “fake@fake.com&#8221;.  Just use a simple confirmation-email method if you need to verify that the user entered a real email address.  It’s so much better.</p>
<p>Besides, most of these fancy schemes aren’t even correct, and can be cumbersome for users.  For instance, many websites out there don’t allow the plus character (“+”) in an email address, even though “+” is a perfectly valid character in an email address. The plus is also a tremendously useful character for advanced Gmail users who use it for spam prevention and email filtering.  Right now, as you read this, there’s probably some programmer out there who thinks he did a stellar job of writing an email validation script that rejects all pluses. All he did was create problems.</p>
<p>For these reasons, my preferred method has always been to just check if the entered email address contains an “at” sign (“@&#8221;).  If it does, I try to send the email.  If not, I tell the user, “Whoops, you’ve made a mistake.”  This catches most errors.   But not all.  It doesn’t catch the billg@microsoft problem.</p>
<p>I searched around a bit and saw that a lot of people are <a href="http://mattiasgeniar.be/2009/02/07/input-validation-using-filter_var-over-regular-expressions/" target="_blank">pimping</a> PHP’s native filter_var() function as a way of validating email addresses.  It goes something like this:</p>
<pre name="code" class="php">
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
      print $_POST['email']. " looks good";
}else{
      print $_POST['email'].   " is a no go";
}
</pre>
<p>That’s great, but after running some tests, I saw that it doesn’t solve the problem of “billg@microsoft”, either.</p>
<p>PHP’s filter_var reports that user@domain (with no TLD) is a valid email address, even though for my purposes, it isn’t.  I think that filter_var is likely technically correct – user@machine is a fine email address, if you happen to be operating within the confines of whatever network “machine” is a part of.  But on the Internet, it’s not gonna get you very far.  On the Internet, user@machine is completely useless.</p>
<p>To make filter_var more suitable for Internet purposes you need to do something like this:</p>
<pre name="code" class="php">
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
         if (preg_match("/\@.+?\../", $_POST['email'])){
            print $_POST['email']. " looks good";
         }else{
            print $_POST['email'].   " is a no go - you forgot the TLD!";
         }
      }else{
         print $_POST['email'].   " is a no go";
      }
}</pre>
<p>The added preg_match line makes sure that there is some character after the @ sign(.), and that a period follows that character(\.), and that another character follows that period (.).</p>
<p>This catches those users who mistakenly left out the TLD, without getting into silly, overly restrictive input validation techniques that often exclude perfectly valid email addresses and are easily circumvented anyway.  And for those users who enter fake addresses – so be it.  Just send a confirmation email and make them click a link to confirm their email address.  You can’t stop people from putting fake info into your form.  All you can do is ask them to verify what they’ve entered.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php" title="How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;">How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;</a></li><li><a href="http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php" title="Getting PHP&#8217;s print_r Function To Return A String">Getting PHP&#8217;s print_r Function To Return A String</a></li><li><a href="http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php" title="PHP Programming: U.S. State list functions / State abbreviation to State name function">PHP Programming: U.S. State list functions / State abbreviation to State name function</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/articles/opera-changes-third-party-iframe-cookie-handing-in-latest-release.php" title="Opera changes third-party iframe cookie handing in latest release">Opera changes third-party iframe cookie handing in latest release</a></li><li><a href="http://www.eddieoneverything.com/programming/how-to-use-global-variables-from-another-file-in-a-perl-module-or-package.php" title="How To Use Global Variables From Another File In A Perl Module or Package">How To Use Global Variables From Another File In A Perl Module or Package</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;</title>
		<link>http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php</link>
		<comments>http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php#comments</comments>
		<pubDate>Fri, 30 Apr 2010 14:55:09 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[nofollow]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpbb]]></category>
		<category><![CDATA[phpbb3]]></category>
		<category><![CDATA[phpbb3 administration]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[search engine ranking]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[serp]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[spam links]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/?p=1161</guid>
		<description><![CDATA[I use phpbb3 for this site&#8217;s discussion area.  It&#8217;s not a particularly popular section of the website, but it does attract one type of commenter &#8211; spammers.
Spammers like to create posts that link to their own site.  They do this for two reasons &#8211; one is to drive traffic directly to their site. [...]]]></description>
			<content:encoded><![CDATA[<p>I use phpbb3 for this site&#8217;s discussion area.  It&#8217;s not a particularly popular section of the website, but it does attract one type of commenter &#8211; spammers.</p>
<p>Spammers like to create posts that link to their own site.  They do this for two reasons &#8211; one is to drive traffic directly to their site.  The other is to increase their Search Engine Results Page ranking (SERP) by adding links to their site.</p>
<p>Search engines use many metrics in determining the position of a page in their search results.  One of those is the number of other websites linking in.  Because of this, there is a great incentive to create links to one&#8217;s own site through spammy comments.  This can have a negative impact on the search engine ranking of my own pages, because a site with a lot of spammy links gets categorized as a spammy site by the search engines, and starts to appear lower on the results pages.</p>
<p>I want to continue to let users post useful links, as I think linking can add to a discussion.  But I also don&#8217;t want to spend a lot of time editing these posts to keep them spam-free.  For that reason, I&#8217;ve modified phpbb3 to include a &#8221; &#8216;rel=&#8217;nofollow&#8217; &#8221; directive on links posted by users, which tells search engines that they shouldn&#8217;t use the fact that my site links to theirs to increase their search engine ranking.</p>
<p>To do so, I had to edit the viewtopic.php file, located in the main phpbb3 directory.  </p>
<p>To make the links on your phpbb3 forum automatically have the &#8220;nofollow&#8221; directive, just search for the following lines, and add preg_replace line, which is #1396 in my example:</p>
<pre name="code" class="php">
   1388    // Second parse bbcode here
   1389    if ($row['bbcode_bitfield'])
   1390    {
   1391       $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
   1392    }
   1393
   1394    $message = bbcode_nl2br($message);
   1395    $message = smiley_text($message);
 1396    $message = preg_replace('/(class="postlink")/','class="postlink" rel="nofollow" target="_blank"',$message);
   1397
</pre>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php" title="Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect">Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect</a></li><li><a href="http://www.eddieoneverything.com/articles/open-source-mybb-has-become-my-forum-of-choice.php" title="Open Source MyBB has become my forum of choice">Open Source MyBB has become my forum of choice</a></li><li><a href="http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php" title="Getting PHP&#8217;s print_r Function To Return A String">Getting PHP&#8217;s print_r Function To Return A String</a></li><li><a href="http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php" title="PHP Programming: U.S. State list functions / State abbreviation to State name function">PHP Programming: U.S. State list functions / State abbreviation to State name function</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/articles/stop-redplum-coupons-from-clogging-up-your-mailbox.php" title="Stop RedPlum Coupons from Clogging Up Your Mailbox">Stop RedPlum Coupons from Clogging Up Your Mailbox</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting PHP&#8217;s print_r Function To Return A String</title>
		<link>http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php</link>
		<comments>http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php#comments</comments>
		<pubDate>Thu, 25 Feb 2010 22:41:42 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[print_r]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/?p=895</guid>
		<description><![CDATA[PHP&#8217;s print_r function is invaluable.  It prints a human-readable string representation of a variable.
It&#8217;s one of the most useful debugging features I&#8217;ve seen in any language.
I like it so much that I&#8217;ve actually written print_r mimic functions for other languages.
By default, print_r literally prints a variable to the screen.  Sometimes it&#8217;s useful to [...]]]></description>
			<content:encoded><![CDATA[<p>PHP&#8217;s print_r function is invaluable.  It prints a human-readable string representation of a variable.</p>
<p>It&#8217;s one of the most useful debugging features I&#8217;ve seen in any language.</p>
<p>I like it so much that I&#8217;ve actually written print_r mimic functions for other languages.</p>
<p>By default, print_r literally <i>prints</i> a variable to the screen.  Sometimes it&#8217;s useful to have that info not printed though.  For instance, you might want to include the print_r result in an email, or an error log, or in a special debugging frame.</p>
<p>Fortunately, print_r has this functionality built in &#8211; the function accepts an optional second argument that specifies whether you want the data printed or returned as a string.</p>
<p>To have print_r return the data as a string, include the second argument &#8220;true&#8221;:</p>
<pre name="code" class="php">
$message = print_r($myObject,true);
</pre>
<p>If you&#8217;re doing anything programmatic with the output, you may want to consider using var_export instead.  This function is largely identical to print_r, except that its output is machine parsable rather than human readable.  The usage is identical to print_r.</p>
<pre name="code" class="php">
$message = var_export($myObject,true);
</pre>
<p>All without using ob_start.  Nice!</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php" title="PHP Programming: U.S. State list functions / State abbreviation to State name function">PHP Programming: U.S. State list functions / State abbreviation to State name function</a></li><li><a href="http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php" title="Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect">Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php" title="How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;">How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;</a></li><li><a href="http://www.eddieoneverything.com/programming/how-to-use-global-variables-from-another-file-in-a-perl-module-or-package.php" title="How To Use Global Variables From Another File In A Perl Module or Package">How To Use Global Variables From Another File In A Perl Module or Package</a></li><li><a href="http://www.eddieoneverything.com/articles/optimizing-the-google-syntax-highlighter-wordpress-plugin-even-further.php" title="Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further">Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further</title>
		<link>http://www.eddieoneverything.com/articles/optimizing-the-google-syntax-highlighter-wordpress-plugin-even-further.php</link>
		<comments>http://www.eddieoneverything.com/articles/optimizing-the-google-syntax-highlighter-wordpress-plugin-even-further.php#comments</comments>
		<pubDate>Wed, 24 Feb 2010 01:22:58 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[google syntax highlighter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress plugins]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/?p=844</guid>
		<description><![CDATA[I use the Google Syntax Highlighter for Wordpress plugin to display the code I share on this page all pretty-like.
The problem is, the thing isn&#8217;t very robust &#8211; it causes every single page on your blog to load up about 10 separate javascript files, regardless of whether the plugin is actually doing anything on that [...]]]></description>
			<content:encoded><![CDATA[<p>I use the <a href="http://wordpress.org/extend/plugins/google-syntax-highlighter/" target="_blank">Google Syntax Highlighter for Wordpress plugin</a> to display the code I share on this page all pretty-like.</p>
<p>The problem is, the thing isn&#8217;t very robust &#8211; it causes every single page on your blog to load up about 10 separate javascript files, regardless of whether the plugin is actually <em>doing anything</em> on that page or not.</p>
<p>I set out to optimize the code, but did a quick search first and found the folks at Fire Studios <a href="http://fire-studios.com/blog/optimizing-the-google-syntax-highlighter-wp-plugin" target="blank">had already beaten me to it</a>. </p>
<p>They have a couple of good tips on their page &#8211; they&#8217;ve combined the separate brush files into a single javascript file, and they&#8217;ve altered the code so that the files are only loaded on single posts and single pages.</p>
<p>That&#8217;s a great fix, but it wasn&#8217;t ideal for my site.  On this site, most of my single posts and pages do not contain any code at all.  So for like 95% of my pages, I don&#8217;t need to load the Google Syntax highlighter at all.</p>
<p>I expanded upon their customization with a further restriction &#8211; in my version, the plugin only loads if the page or post contains certain tags &#8211; namely &#8220;code&#8221;, &#8220;programming&#8221;, &#8220;perl&#8221;, &#8220;php&#8221;, &#8220;javascript&#8221;, or &#8220;python&#8221;, the tags I normally use when sharing a piece of code.</p>
<p><b>My google_syntax_highlighter.php file</b></p>
<pre name="code" class="php">
function insert_header() {
   $current_path = get_option('siteurl') .'/wp-content/plugins/' . basename(dirname(__FILE__)) .'/';

    if(is_single() &#038;&#038; has_tag(array('code','javascript','perl','python','php','programming'))){
   ?>
<link href="Styles/SyntaxHighlighter.css" type="text/css" rel="stylesheet"
/>
   &lt;?php
   }
}

function insert_footer(){
   $current_path = get_option('siteurl') .'/wp-content/plugins/' . basename(dirname(__FILE__)) .'/';
    if(is_single() &#038;&#038; has_tag(array('code','javascript','perl','python','php','programming'))){
   ?>
<script class="javascript" src="Scripts/shCore.js"></script>
<script class="javascript" src="Scripts/shBrushAll.js"></script>
<script class="javascript">
dp.SyntaxHighlighter.ClipboardSwf = 'Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script>
&lt;?php
   }
}
add_action('wp_head','insert_header');
add_action('wp_footer','insert_footer');
</pre>
<p>Of course, you may want to use different tags, depending on your setup.  </p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php" title="Getting PHP&#8217;s print_r Function To Return A String">Getting PHP&#8217;s print_r Function To Return A String</a></li><li><a href="http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php" title="PHP Programming: U.S. State list functions / State abbreviation to State name function">PHP Programming: U.S. State list functions / State abbreviation to State name function</a></li><li><a href="http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php" title="Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect">Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect</a></li><li><a href="http://www.eddieoneverything.com/articles/managing-server-load-when-unzipping-many-large-files.php" title="Managing Server Load when unzipping many large files">Managing Server Load when unzipping many large files</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/disabling-textarea-scrolling-in-flash-as3.php" title="Disabling TextArea Scrolling in Flash AS3">Disabling TextArea Scrolling in Flash AS3</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/articles/optimizing-the-google-syntax-highlighter-wordpress-plugin-even-further.php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Programming: U.S. State list functions / State abbreviation to State name function</title>
		<link>http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php</link>
		<comments>http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php#comments</comments>
		<pubDate>Thu, 13 Nov 2008 02:13:09 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php</guid>
		<description><![CDATA[Here are a few PHP functions that I find useful for United States related things.  Nothing brilliant or groundbreaking &#8211; just something to save you some typing.
1. A PHP function for printing a state select box
2. A PHP function that returns the full state name when passed the abbreviation
3. A PHP snippet for printing [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a few PHP functions that I find useful for United States related things.  Nothing brilliant or groundbreaking &#8211; just something to save you some typing.</p>
<p>1. A PHP function for printing a state select box<br />
2. A PHP function that returns the full state name when passed the abbreviation<br />
3. A PHP snippet for printing a state select box</p>
<p>This function prints a state select box.  It accepts the name of the box and the abbreviation of the state that you want selected.</p>
<pre name="code" class="php">
   function printStateSelectBox($name, $selected){
      $state_arr=array( "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC",
         "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA",
         "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE",
         "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC",
         "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY");

      $ret="
<select name=\"$name\">";
      if (!$selected){
         $ret.="<option value=\"\" > </option>\n";
      }else{
         $ret.="<option value=\"\" selected=\"selected\"> </option>\n";
      }

      foreach ($state_arr as $state){
         if ($selected==$state){
            $ret.="<option value=\"$state\" selected=\"selected\">$state</option>\n";
         }else{
            $ret.="<option value=\"$state\">$state</option>\n";
         }
      }

      $ret.="</select>

";
      //print "selected is $selected";
      return ($ret);
   }
</pre>
<p>This function returns the state name when passed the abbreviation.</p>
<pre name="code" class="php">
 function getStateNameByAbbreviation($state){
      if ($state=="AK"){ return "Alaska"; }
      if ($state=="AL"){ return "Alabama"; }
      if ($state=="AR"){ return "Arkansas"; }
      if ($state=="AZ"){ return "Arizona"; }
      if ($state=="CA"){ return "California"; }
      if ($state=="CO"){ return "Colorado"; }
      if ($state=="CT"){ return "Connecticut"; }
      if ($state=="DC"){ return "District of Columbia"; }
      if ($state=="DE"){ return "Delaware"; }
      if ($state=="FL"){ return "Florida"; }
      if ($state=="GA"){ return "Georgia"; }
      if ($state=="HI"){ return "Hawaii"; }
      if ($state=="IA"){ return "Iowa"; }
      if ($state=="ID"){ return "Idaho"; }
      if ($state=="IL"){ return "Illinois"; }
      if ($state=="IN"){ return "Indiana"; }
      if ($state=="KS"){ return "Kansas"; }
      if ($state=="KY"){ return "Kentucky"; }
      if ($state=="LA"){ return "Louisiana"; }
        if ($state=="MA"){ return "Massachusetts"; }
        if ($state=="MD"){ return "Maryland"; }
        if ($state=="ME"){ return "Maine"; }
        if ($state=="MI"){ return "Michigan"; }
        if ($state=="MN"){ return "Minnesota"; }
        if ($state=="MO"){ return "Missouri"; }
        if ($state=="MS"){ return "Mississippi"; }
        if ($state=="MT"){ return "Montana"; }
        if ($state=="NC"){ return "North Carolina"; }
        if ($state=="ND"){ return "North Dakota"; }
        if ($state=="NE"){ return "Nebraska"; }
        if ($state=="NH"){ return "New Hampshire"; }
        if ($state=="NJ"){ return "New Jersey"; }
        if ($state=="NM"){ return "New Mexico"; }
        if ($state=="NV"){ return "Nevada"; }
        if ($state=="NY"){ return "New York"; }
        if ($state=="OH"){ return "Ohio"; }
        if ($state=="OK"){ return "Oklahoma"; }
        if ($state=="OR"){ return "Oregon"; }
        if ($state=="PA"){ return "Pennsylvania"; }
        if ($state=="RI"){ return "Rhode Island"; }
        if ($state=="SC"){ return "South Carolina"; }
        if ($state=="SD"){ return "South Dakota"; }
        if ($state=="TN"){ return "Tennessee"; }
        if ($state=="TX"){ return "Texas"; }
        if ($state=="UT"){ return "Utah"; }
        if ($state=="VA"){ return "Virginia"; }
        if ($state=="VT"){ return "Vermont"; }
        if ($state=="WA"){ return "Washington"; }
        if ($state=="WI"){ return "Wisconsin"; }
        if ($state=="WV"){ return "West Virginia"; }
      if ($state=="WY"){ return "Wyoming"; }

   }
</pre>
<p>Another snippet for printing a State select box.  </p>
<pre name="code" class="php">
$state_list = array('AL'=>"Alabama",  'AK'=>"Alaska",  'AZ'=>"Arizona",  'AR'=>"Arkansas", 'CA'=>"California",  'CO'=>"Colorado",  'CT'=>"Connecticut",  'DE'=>"Delaware",'DC'=>"District Of Columbia",  'FL'=>"Florida",  'GA'=>"Georgia",  'HI'=>"Hawaii", 'ID'=>"Idaho",  'IL'=>"Illinois",  'IN'=>"Indiana",  'IA'=>"Iowa",  'KS'=>"Kansas", 'KY'=>"Kentucky",  'LA'=>"Louisiana",  'ME'=>"Maine",  'MD'=>"Maryland", 'MA'=>"Massachusetts",  'MI'=>"Michigan",  'MN'=>"Minnesota",  'MS'=>"Mississippi", 'MO'=>"Missouri",  'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio",  'OK'=>"Oklahoma",  'OR'=>"Oregon",'PA'=>"Pennsylvania",  'RI'=>"Rhode Island",  'SC'=>"South Carolina",  'SD'=>"South Dakota", 'TN'=>"Tennessee",  'TX'=>"Texas",  'UT'=>"Utah",  'VT'=>"Vermont",  'VA'=>"Virginia", 'WA'=>"Washington",  'WV'=>"West Virginia",  'WI'=>"Wisconsin",  'WY'=>"Wyoming");

foreach ($state_list as $k=>$v){
   if ($k == $select){
      $sv=" SELECTED ";
   }else{
      $sv="";
   }
   print " <option value=\"$k\" $sv>$k</option>";
}
</pre>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php" title="Getting PHP&#8217;s print_r Function To Return A String">Getting PHP&#8217;s print_r Function To Return A String</a></li><li><a href="http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php" title="Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect">Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php" title="How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;">How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;</a></li><li><a href="http://www.eddieoneverything.com/programming/how-to-use-global-variables-from-another-file-in-a-perl-module-or-package.php" title="How To Use Global Variables From Another File In A Perl Module or Package">How To Use Global Variables From Another File In A Perl Module or Package</a></li><li><a href="http://www.eddieoneverything.com/articles/optimizing-the-google-syntax-highlighter-wordpress-plugin-even-further.php" title="Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further">Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Uploading Large Files to a LAMP setup &#8211; upload_max_filesize, post_max_size, and max_allowed_packet</title>
		<link>http://www.eddieoneverything.com/linux/uploading-large-files-to-a-lamp-setup-upload_max_filesize-post_max_size-and-max_allowed_packet.php</link>
		<comments>http://www.eddieoneverything.com/linux/uploading-large-files-to-a-lamp-setup-upload_max_filesize-post_max_size-and-max_allowed_packet.php#comments</comments>
		<pubDate>Fri, 28 Dec 2007 16:57:02 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[filesize]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[L.A.M.P.]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[max_allowed_packet]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqld]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[post_max_size]]></category>
		<category><![CDATA[uploading files]]></category>
		<category><![CDATA[upload_max_filesize]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/linux/uploading-large-files-to-a-lamp-setup-upload_max_filesize-post_max_size-and-max_allowed_packet.php</guid>
		<description><![CDATA[So you&#8217;re trying to upload a large file via PHP and you&#8217;re getting an error, eh?  It&#8217;s probably because of PHP&#8217;s default configuration, which limits uploads to 2 Megs, or because of MySQL&#8217;s default 1.5 Meg limitation.  Here&#8217;s how you change these defaults.
First, find your php.ini file.  If you don&#8217;t know where [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense--><br />
So you&#8217;re trying to upload a large file via PHP and you&#8217;re getting an error, eh?  It&#8217;s probably because of PHP&#8217;s default configuration, which limits uploads to 2 Megs, or because of MySQL&#8217;s default 1.5 Meg limitation.  Here&#8217;s how you change these defaults.</p>
<p>First, find your php.ini file.  If you don&#8217;t know where it is, create a php file on your server that contains only the following:</p>
<p><code>&lt;? phpinfo(); ?&gt;</code></p>
<p>Load that up in your browser and look for the line that says<br />
<code>Configuration File (php.ini) Path</code></p>
<p>It&#8217;s probably set to something like /usr/local/lib/php.ini.</p>
<p>Once found, open up this file and edit the following lines as you see fit:<br />
<code>file_uploads = On<br />
upload_max_filesize = 30M<br />
post_max_size = 30M</code></p>
<p>In the above example, I&#8217;ve updated my configuration to allow uploads of up to 30 Megs.</p>
<p>Once this is complete, restart apache (using something like &#8220;/etc/init.d/httpd restart&#8221;) and voila, the file upload size limitation should be lifted.</p>
<p>If you&#8217;re trying to insert this large uploaded file into a MySQL database, you may, at this time, run into a second limitation:</p>
<blockquote><p>An error has occured uploading that fileGot a packet bigger than &#8216;max_allowed_packet&#8217; bytes<br />
SQL: INSERT INTO &#8230;</p></blockquote>
<p>That&#8217;s because mysql also has a limit on how large a single SQL query can be.  This, too, can be raised &#8211; I edited my mysql configuration file at /etc/my.cnf and changed the max_allowed_packet size to 30M as well:</p>
<p><code>max_allowed_packet = 30M</code></p>
<p>After doing so, simply restart mysql using something like &#8220;/etc/init.d/mysql restart&#8221; and the problem should disappear.<br />
<!--adsense#468banner--></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/articles/linux-forward-file-not-working-make-sure-you-have-the-permissions-set-correctly.php" title="Linux .forward file not working?  Make sure you have the permissions set correctly">Linux .forward file not working?  Make sure you have the permissions set correctly</a></li><li><a href="http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php" title="Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect">Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect</a></li><li><a href="http://www.eddieoneverything.com/articles/managing-server-load-when-unzipping-many-large-files.php" title="Managing Server Load when unzipping many large files">Managing Server Load when unzipping many large files</a></li><li><a href="http://www.eddieoneverything.com/linux/caution-filename-not-matched-error-when-unzipping-multiple-files-workaround.php" title="Caution: filename not matched error when unzipping multiple files workaround">Caution: filename not matched error when unzipping multiple files workaround</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php" title="How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;">How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/linux/uploading-large-files-to-a-lamp-setup-upload_max_filesize-post_max_size-and-max_allowed_packet.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

