<?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>Bram.us &#187; PHP Willow Tree</title>
	<atom:link href="http://www.bram.us/category/php-willow-tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bram.us</link>
	<description>A rather geeky/technical weblog by Bram(us) Van Damme</description>
	<lastBuildDate>Sat, 04 Feb 2012 11:59:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>My inc.functions.php &#8211; Part 4 : Unshifting elements on an array and preserving keys</title>
		<link>http://www.bram.us/2007/11/19/my-incfunctionsphp-part-4-unshifting-elements-on-an-array-and-preserving-keys/</link>
		<comments>http://www.bram.us/2007/11/19/my-incfunctionsphp-part-4-unshifting-elements-on-an-array-and-preserving-keys/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 21:42:16 +0000</pubDate>
		<dc:creator>Bramus!</dc:creator>
				<category><![CDATA[Discovery Of The Day]]></category>
		<category><![CDATA[PHP Willow Tree]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<guid isPermaLink="false">http://www.bram.us/2007/11/19/my-incfunctionsphp-part-4-unshifting-elements-on-an-array-and-preserving-keys/</guid>
		<description><![CDATA[The fourth part of this series of handy little PHP functions only contains a little tip when one needs to add an element to the beginning of an array (viz. prepend, unshift) but has to preserve the (numerical) keys. Prerequisites &#8230; <a href="http://www.bram.us/2007/11/19/my-incfunctionsphp-part-4-unshifting-elements-on-an-array-and-preserving-keys/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img id="image315" src="http://www.bram.us/wordpress/wp-content/uploads/2006/11/php_willowtree.jpg" alt="PHP Willow Tree" title="PHP Willow Tree" style="margin: 5px 10px 2px 0px; display: block; float: left;" />The fourth part of <a href="http://www.bram.us/category/php-willow-tree/">this series of handy little PHP functions</a> only contains a little tip when one needs to add an element to the beginning of an array (viz. prepend, unshift) but has to preserve the (numerical) keys.<br style="clear: both;" /></p>
<p><span id="more-1255"></span></p>
<h2>Prerequisites</h2>
<div class="BramusBlock">
<p>Imagine you have an array of zipcodes as keys and names of cities as values:</p>
<pre class="brush: php; title: ; notranslate">$zipcodes = array(
	'9800' =&gt; 'Deinze',
	'8460' =&gt; 'Ettelgem',
	'9000' =&gt; 'Gent',
	'8400' =&gt; 'Oostende'
);</pre>
<p>Now, if I were to place those into a dropdown, I&#8217;d run that array to a function like so:</p>
<pre class="brush: php; title: ; notranslate">function createDropdown($ddName, $arValues) {
	$toReturn = &quot;&lt;select name=\&quot;$ddName\&quot; id=\&quot;$ddName\&quot;&gt;\n&quot;;
	foreach ($arValues as $key =&gt; $value) {
		$toReturn .= &quot;\t&lt;option value=\&quot;$key\&quot;&gt;$value&lt;/option&gt;\n&quot;;
	}
	$toReturn .= &quot;&lt;/select&gt;&quot;;
	return $toReturn;
}</pre>
<p>Running the array above through that function would result in the following HTML:</p>
<pre class="brush: xml; title: ; notranslate">&lt;!-- output of echo createDropdown(&quot;test&quot;, $zipcodes); --&gt;
&lt;select name=&quot;test&quot; id=&quot;test&quot;&gt;
	&lt;option value=&quot;9800&quot;&gt;Deinze&lt;/option&gt;
	&lt;option value=&quot;8460&quot;&gt;Ettelgem&lt;/option&gt;
	&lt;option value=&quot;9000&quot;&gt;Gent&lt;/option&gt;
	&lt;option value=&quot;8400&quot;&gt;Oostende&lt;/option&gt;
&lt;/select&gt;</pre>
<p>Quite obvious, not?</p>
</div>
<h2 style="margin-top: 12px;">The problem</h2>
<div class="BramusBlock">
<p>Now, I don&#8217;t want to have &ldquo;Deinze&rdquo; show up in the dropdown as the first item, but I want to show &ldquo;Please choose your city&rdquo; as the first item (with a value of 0). A quick peek at the PHP docs tell me that I need to use <code><a href="http://www.php.net/array_unshift">array_unshift</a></code> to &ldquo;<em>prepend one or more elements to the beginning of an array</em>&rdquo;</p>
<pre class="brush: plain; title: ; notranslate">array_unshift($zipcodes, &quot;Please Choose a City&quot;);</pre>
<p>Running the code above would float my boat, right? Wrong! The note at the phpdocs that &ldquo;<em>All numerical array keys will be modified to start counting from zero while literal keys won&#8217;t be touched</em>&rdquo;. After having run <code>array_unshift</code> on <code>$zipcodes</code> it indeed looks like this:</p>
<pre class="brush: plain; title: ; notranslate">Array
(
    [0] =&gt; Please Choose a City
    [1] =&gt; Deinze
    [2] =&gt; Ettelgem
    [3] =&gt; Gent
    [4] =&gt; Oostende
)</pre>
</div>
<h2 style="margin-top: 12px;">The solution</h2>
<div class="BramusBlock">
<p>The solution is to create a second array with only one item (index: &ldquo;0&rdquo;, value: &ldquo;Please choose a city&rdquo; and then merge them together, but not using the <code><a href="http://www.php.net/array_merge">array_merge</a></code> function as the function looses numerical keys too!</p>
<p>So what does one need to use then? Well, it might sound <a href="http://www.google.com/search?q=define%3A+noobcake">noobcake</a>-ish to you but this one I didn&#8217;t know: <strong>one can actually join 2 arrays in PHP by using the mathematical + operator</strong>! Now this is something I did not expect (it looks so not-PHP-alike, not?)!</p>
<pre class="brush: php; title: ; notranslate">$zipcodes = array(&quot;0&quot; =&gt; &quot;Please Choose a City&quot;) + $zipcodes;</pre>
<p>And yes, the array now looks like:</p>
<pre class="brush: plain; title: ; notranslate">Array
(
    [0] =&gt; Please Choose a City
    [9800] =&gt; Deinze
    [8460] =&gt; Ettelgem
    [9000] =&gt; Gent
    [8400] =&gt; Oostende
)</pre>
<p>And the HTML output after running the array through the <code>createDropdown</code> function looks like:</p>
<pre class="brush: xml; title: ; notranslate">&lt;select name=&quot;test&quot; id=&quot;test&quot;&gt;
	&lt;option value=&quot;0&quot;&gt;Please Choose a City&lt;/option&gt;
	&lt;option value=&quot;9800&quot;&gt;Deinze&lt;/option&gt;
	&lt;option value=&quot;8460&quot;&gt;Ettelgem&lt;/option&gt;
	&lt;option value=&quot;9000&quot;&gt;Gent&lt;/option&gt;
	&lt;option value=&quot;8400&quot;&gt;Oostende&lt;/option&gt;
&lt;/select&gt;</pre>
</div>
<h2 style="margin-top: 12px;">Wrapping up</h2>
<div class="BramusBlock">
<p>To finalize, one could wrap this little trick into a function and presto, but since it would take more code to join 2 arrays through a custom built function (which only uses a + operator) it&#8217;s way more easy to &ldquo;<em>just</em>&rdquo; remember this little trick <img src='http://www.bram.us/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bram.us/2007/11/19/my-incfunctionsphp-part-4-unshifting-elements-on-an-array-and-preserving-keys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My inc.functions.php &#8211; Part 3 : Nicer Summaries with reworkSummary()</title>
		<link>http://www.bram.us/2007/01/11/my-incfunctionsphp-part-3-nicer-summaries-with-reworksummary/</link>
		<comments>http://www.bram.us/2007/01/11/my-incfunctionsphp-part-3-nicer-summaries-with-reworksummary/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 20:28:43 +0000</pubDate>
		<dc:creator>Bramus!</dc:creator>
				<category><![CDATA[Another Dailie]]></category>
		<category><![CDATA[PHP Willow Tree]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<guid isPermaLink="false">http://www.bram.us/2007/01/11/my-incfunctionsphp-part-3-nicer-summaries-with-reworksummary/</guid>
		<description><![CDATA[In the third part of this series of handy little PHP functions I&#8217;ll be describing a darn little function that only has an impact on the aesthetics of a site. Of summaries and such Imagine you have a site that &#8230; <a href="http://www.bram.us/2007/01/11/my-incfunctionsphp-part-3-nicer-summaries-with-reworksummary/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img id="image315" src="http://www.bram.us/wordpress/wp-content/uploads/2006/11/php_willowtree.jpg" alt="PHP Willow Tree" title="PHP Willow Tree" style="margin: 5px 10px 2px 0px; display: block; float: left;" />In the third part of <a href="http://www.bram.us/category/php-willow-tree/">this series of handy little PHP functions</a> I&#8217;ll be describing a darn little function that only has an impact on the aesthetics of a site.</p>
<p style="clear: both;"><span id="more-357"></span></p>
<h3>Of summaries and such</h3>
<div class="BramusBlock">
<p>Imagine you have a site that has a sidebar containing <em>auto-generated summaries</em> of (news)items, as seen on <a href="http://www.snook.ca/jonathan/">Jonathan Snook&#8217;s blog</a> for example</p>
<p style="text-align: center;"><a href="http://www.snook.ca/jonathan/"><img id="image363" src="http://www.bram.us/wordpress/wp-content/uploads/2007/01/snook_ca_jonathan_2007_01_1.jpg" title="Jonathan Snook's Blog" alt="Jonathan Snook's Blog" /></a></p>
<p style="font-size: smaller;">(I could have referred to some other sites, yet Jonathan&#8217;s blog is perfect to highlight the <em>why</em> of this function)</em></p>
<p>If you take a closer look at the summaries you&#8217;ll see that they all are cut at about the 200th character:</p>
<blockquote><p><em>I had a few things I wanted to mention and separate posts about each didn&#8217;t seem warranted so here it is: 3 days left! The SXSW 2007 Interactive Pass Contest was off to a strong start with a bunch &#8230;</em></p>
</blockquote>
<p>Above that the summary is a flat version of the actual post: in the <a href="http://www.snook.ca/archives/other/update_2007-01-09/">full news/blogpost of the item quoted above</a> you&#8217;ll see that <strong>3 days left!</strong> is a heading for example.</p>
</div>
<h3>Freebie: creating the summary</h3>
<div class="BramusBlock">
<p>Before getting to <em>reworkSummary()</em>, a function to create  a summary is needed. This is actually plain simple:</p>
<ul>
<li>Enforce the string to be HTML (thus the opposite of htmlentities())</li>
<li>Strip out the HTML (that&#8217;s why the string had to be enforced to be HTML)</li>
<li>Cut at the 200th character</li>
</ul>
<p>The order of these steps are important, since otherwise one would be able to cut right in between an xhtml tag&#8230;</p>
<p>The PHP code for this is even more easy.</p>
<pre class="brush: php; title: ; notranslate">
// All your code are belong to bram.us
	function makeSummary($text, $length, $hellip = &quot;&amp;hellip;&quot;) {
		// enforce html text (maybe it was encoded somewhere)
		$htmlText	= html_entity_decode($text);
		// strip out the tags
		$flatText	= strip_tags($htmlText);
		// text is not longer than length, return flatText
		if (strlen($flatText) &lt;= $length) {
			return $flatText;
		// text is longer than length, create the summary and add hellips
		} else {
			$summary	= substr($flatText, 0, $length);
			return $summary.$hellip;
		}
	}
</pre>
<p>With the addition of the horizontal ellipsis at the end (to indicate that there&#8217;s more to read) we&#8217;re done, right?</p>
</div>
<h3>And now &#8230; the carbomb (Dr. Dre)</h3>
<div class="BramusBlock">
<p>Wrong! In the example quote way at the top, you&#8217;ll see that the summary was cut just after a word, yet some other summaries are cut right in the middle or a word, for example:</p>
<blockquote><p><em>This seems to bite me in the ass more often than not but any time you add a new model or adjust your associations, be sure to delete the cached ones from the /app/tmp/ folder. I&#8217;ll get inexplicable er&#8230;</em></p>
</blockquote>
<p>Not that nice indeed.</p>
<p>Now I must say that I myself hadn&#8217;t noticed this, it was only until <a href="http://www.mediadesk.nl/" title="MEDIA Desk Nederland">a client of ours</a> made me aware of it <a href="http://www.wax.be/index.php?p=/portfolio/detail/media-desk-nederland-website/6/">whilst developing their site</a> that I saw it. And boy I must say, <em>she</em> sure was right: it does look pretty nasty when a word is cut in half and the horizontal ellipsis is placed right after that. *Yoink*</p>
<p style="text-align: center;"><a href="http://www.mediadesk.nl/" title="MEDIA Desk Nederland"><img id="image364" src="http://www.bram.us/wordpress/wp-content/uploads/2007/01/mediadesk_nl.jpg" title="MEDIA Desk Nederland" alt="MEDIA Desk Nederland" /></a></p>
<p>Solution for this problem actually is &quot;as easy as killing babies with axes&quot;: just cut off the summary on the last space and you&#8217;re done (there would a problem if no space occurs, yet that won&#8217;t occur on a regular news-/blogpost). So next to the makeSummary() function we&#8217;ll create a reworkSummary() function to take the appropriate actions.</p>
<p>The resulting PHP code for this is:</p>
<pre class="brush: php; title: ; notranslate">
// All your code are belong to bram.us
	function reworkSummary($summary) {
		// find last space
		$pos = strrpos($summary, &quot; &quot;);
		// a space was found: return substring from 0 till found position
		if ($pos !== false) {
			return substr($summary, 0, $pos);
		// no space was found: return the created summary
		} else {
			return $summary;
		}
	}
</pre>
<p>Now all you have to do is adjust makeSummary() so that it calls the reworkSummary() function. Please note that the default horizontal ellipsis now is preceded with a space, to make it look even nicer:</p>
<pre class="brush: php; title: ; notranslate">
// All your code are belong to bram.us
	function makeSummary($text, $length, $hellip = &quot; &amp;hellip;&quot;) {
		// enforce html text (maybe it was encoded somewhere)
		$htmlText	= html_entity_decode($text);
		// strip out the tags
		$flatText	= strip_tags($htmlText);
		// text is not longer than length, return flatText
		if (strlen($flatText) &lt;= $length) {
			return $flatText;
		// text is longer than length, create the summary and add hellips
		} else {
			$summary	= substr($flatText, 0, $length);
			return reworkSummary($summary).$hellip;
		}
	}
</pre>
</div>
<h3>Code example:</h3>
<div class="BramusBlock">
<p>The following code &#8230;</p>
<pre class="brush: php; title: ; notranslate">echo makeSummary(&quot;Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.&quot;, 200);
echo makeSummary(&quot;Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.&quot;, 200, &quot; (continued)&quot;);
echo makeSummary(&quot;Lorem Ipsum is simply dummy text of the printing and typesetting industry.&quot;, 200, &quot; (continued)&quot;);</pre>
<p>&#8230; will output:</p>
<pre class="brush: xml; title: ; notranslate">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type &amp;hellip;
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type (continued)
Lorem Ipsum is simply dummy text of the printing and typesetting industry.</pre>
<p>Happy summarizing!</p>
<p>B!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bram.us/2007/01/11/my-incfunctionsphp-part-3-nicer-summaries-with-reworksummary/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>My inc.functions.php &#8211; Part 2 : Creating a post slug</title>
		<link>http://www.bram.us/2006/12/18/my-incfunctionsphp-part-2-creating-a-post-slug/</link>
		<comments>http://www.bram.us/2006/12/18/my-incfunctionsphp-part-2-creating-a-post-slug/#comments</comments>
		<pubDate>Mon, 18 Dec 2006 22:25:02 +0000</pubDate>
		<dc:creator>Bramus!</dc:creator>
				<category><![CDATA[Another Dailie]]></category>
		<category><![CDATA[PHP Willow Tree]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<guid isPermaLink="false">http://www.bram.us/2006/12/18/my-incfunctionsphp-part-2-creating-a-post-slug/</guid>
		<description><![CDATA[In the second part of this series (Click for part 1) another tiny, yet handy PHP function is described. Some of you might already have discovered the power of having a &#34;post slug&#34; in an URI. Not only does a &#8230; <a href="http://www.bram.us/2006/12/18/my-incfunctionsphp-part-2-creating-a-post-slug/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img id="image315" src="http://www.bram.us/wordpress/wp-content/uploads/2006/11/php_willowtree.jpg" alt="PHP Willow Tree" title="PHP Willow Tree" style="margin: 5px 10px 2px 0px; display: block; float: left;" />In the second part of this series (<a href="http://www.bram.us/2006/11/30/my-incfunctionsphp-part-1-fixing-those-gmailcom-e-mail-addresses/" title="My inc.functions.php - Part 1 : Fixing those gmail.com e-mail addresses, a post on Bram.us">Click for part 1</a>) another tiny, yet handy PHP function is described. Some of you might already have discovered the power of having a &quot;<dfn title="A a shorthand version of the post's title with certain characters escaped or dropped.">post slug</dfn>&quot; in an URI. Not only does a post slug give an indication to the user (he can tell by the URI what the post/link is all about), it also improves your ranking within search engines as they mark a word in the URI as being important and relevant.</p>
<p style="clear: both;"><span id="more-342"></span></p>
<p>Basically a post slug only contains the alphanumerical characters and spaces get replaced by dashes. Above that it&#8217;s lowercase.</p>
<p>These 3 criteria can easily be achieved by using a regular expression to filter out the alphanumerical characters, followed by a simple str_replace to replace all spaces by dashes and finally followed by a lowercase() call.</p>
<pre class="brush: php; title: ; notranslate">// Bramus! pwnge! : simple method to create a post slug (http://www.bram.us/)
	function fixForUri($string) {
		$slug = preg_replace(&quot;/[^a-zA-Z0-9 -]/&quot;, &quot;&quot;, $string); // only take alphanumerical characters, but keep the spaces and dashes too...
		$slug = str_replace(&quot; &quot;, &quot;-&quot;, $slug); // replace spaces by dashes
		$slug = strtolower($slug);	// make it lowercase
		return $slug;
	}</pre>
<p>The function itself can of course be written into a single line, yet to make it all more readable it has been spread out. One call per line.</p>
<p>The reason I&#8217;ve named the function fixForUri() is due to the fact that the function actually fixes any given string for usage in an URI</p>
<p>Happy coding!</p>
<p>B!</p>
<p style="font-size: smaller">Oh yeah, the next function coming up in this series will be a pure aesthetic one &#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bram.us/2006/12/18/my-incfunctionsphp-part-2-creating-a-post-slug/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>My inc.functions.php &#8211; Part 1 : Fixing those gmail.com e-mail addresses.</title>
		<link>http://www.bram.us/2006/11/30/my-incfunctionsphp-part-1-fixing-those-gmailcom-e-mail-addresses/</link>
		<comments>http://www.bram.us/2006/11/30/my-incfunctionsphp-part-1-fixing-those-gmailcom-e-mail-addresses/#comments</comments>
		<pubDate>Thu, 30 Nov 2006 20:04:42 +0000</pubDate>
		<dc:creator>Bramus!</dc:creator>
				<category><![CDATA[Another Dailie]]></category>
		<category><![CDATA[PHP Willow Tree]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<guid isPermaLink="false">http://www.bram.us/2006/11/30/my-incfunctionsphp-part-1-fixing-those-gmailcom-e-mail-addresses/</guid>
		<description><![CDATA[After seeing Shaun&#8217;s Fixing the $_FILES superglobal I found myself browsing around in the inc.functions.php file I&#8217;ve been using and maintaining project by project. To my own surprise I noticed that the file itself has grown over time and kind &#8230; <a href="http://www.bram.us/2006/11/30/my-incfunctionsphp-part-1-fixing-those-gmailcom-e-mail-addresses/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img id="image315" src="http://www.bram.us/wordpress/wp-content/uploads/2006/11/php_willowtree.jpg" alt="PHP Willow Tree" title="PHP Willow Tree" style="margin: 5px 10px 2px 0px; display: block; float: left;" />After seeing <a href="http://www.shauninman.com/post/heap/2006/11/30/fixing_the_files_superglobal" title="">Shaun&#8217;s Fixing the $_FILES superglobal</a> I found myself browsing around in the inc.functions.php file I&#8217;ve been using and maintaining project by project. To my own surprise I noticed that the file itself has grown over time and kind of is stuffed with some darn handy functions! Time to spread them out, starting with this one right here: fixGmail();</p>
<p><span id="more-314"></span></p>
<p>Whilst <a href="http://www.bram.us/2006/05/11/my-view-on-iedereenleeftmeebe/" title="My view on Iedereenleeftmee.be - A post on Bram.us">coding Iedereenleeftmee back in May</a> fixGmail() was created to rework gmail.com addresses. Reason for reworking all those addresses was the fact that Iedereenleeftmee was/is based upon unique e-mail addresses. But what is there to rework on an e-mail address? And why only GMail?</p>
<p>As one might know, gmail accounts are in and have some bugs the Google team would like to call features:</p>
<ul>
<li>Period Stuffing</li>
<li>Plussing</li>
</ul>
<h3>Period Stuffing</h3>
<div class="BramusBlock">
<p>Period Stuffing &#8211; as I like to call it &#8211; implies that <a href="http://mail.google.com/support/bin/answer.py?answer=10313&#038;topic=1564" title="">periods can be added anywhere in the username without affecting it at all</a></p>
<p>For example think of me having bram@gmail.com (which I don&#8217;t!). The first &quot;feature&quot; implies that all of the following e-mail addresses will arrive to bram@gmail.com:</p>
<ul>
<li>b.ram@gmail.com</li>
<li>br.am@gmail.com</li>
<li>bra.m@gmail.com</li>
<li>b.r.am@gmail.com</li>
<li>&#8230;</li>
<li>Heck, even &quot;<em>b&#8230;&#8230;ram@gmail.com</em>&quot; would arrive!</li>
</ul>
<p>As you can see this was an issue with Iedereenleeftmee since some handy dudes would just invite themselves 9 times (with each having a period on a different spot), thus receiving 10 free entrance tickets to an amusement park of choice.</p>
</div>
<h3>Plussing</h3>
<div class="BramusBlock">
<p>Plussing can be taken quite literally: use a plus sign (+) to add an extra parameter/piece of text to to your e-mail address</p>
<p>Take that bram@gmail.com account again &#8230; what if I had to subscribe to some forum leaving behind my e-mail address. How would I ever possibly know if they sold/gave my e-mailaddy to someone else? This is where PA kicks in: one can actually enter bram+thatgamesforum@gmail.com and the mails would still arriving! Quite handy imo (so you can really track who&#8217;s selling what and/or even filter some stuff), yet not handy for the webdeveloper who wants users to be unique by their e-mailaddress&#8230;</p>
</div>
<h3>The PHP Code</h3>
<div class="BramusBlock">
<p>The PHP Code is quite simple and laid upon thee here for grabbing:</p>
<pre class="brush: php; title: ; notranslate">
// Bramus! pwnge! : fixes gmail.com mail addresses (http://www.bram.us/)
function fixGmail($emailaddy) {
	// $emailaddy is an '@gmail.com'-address
	if (eregi('@gmail.com', $emailaddy)) {
		// make lowercase, strip out periods (but fix gmailcom)
		$emailaddy	= str_replace(&quot;@gmailcom&quot;,&quot;@gmail.com&quot;,str_replace(&quot;.&quot;, &quot;&quot;, strtolower($emailaddy)));
		// a plus sign is found in $emailaddy
		if (eregi('\+', $emailaddy)) {
			// grab the substring from the start up to the first plus sign and add @gmail.com
			$emailaddy	= substr($emailaddy,0, strpos($emailaddy,&quot;+&quot;)).&quot;@gmail.com&quot;;
		}
	}
	// now return it
	return $emailaddy;
}
</pre>
<p>Successfully tested with a series of e-mail addresses, all resulting bram@gmail.com</p>
<ul>
<li>bram@gmail.com</li>
<li>b.r.am@gmail.com</li>
<li>b.r&#8230;..am@gmail.com</li>
<li>bram+newsgroups@gmail.com</li>
<li>bram+forum@gmail.com</li>
<li>b.ram+extra@gmail.com</li>
<li>b.r.am+extra@gmail.com</li>
<li>b.ram+ex..tra@gmail.com</li>
<li>b.r.am+ex+t.ra@gmail.com</li>
</ul>
</div>
<h3>That&#8217;s it for now&#8230;</h3>
<div class="BramusBlock">
<p>Stay tuned for more PHP Geekery!</p>
<p>B!</p>
</div>
<p style="font-size: 9px;">(post scriptum: Icon companioning this post is a Willow Tree, influenced by <a href="http://www.muzic.net.nz/artists/235.html" title="">Fat Freddy&#8217;s Drop!</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bram.us/2006/11/30/my-incfunctionsphp-part-1-fixing-those-gmailcom-e-mail-addresses/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

