<?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>Beaver6813.com &#187; php</title>
	<atom:link href="http://beaver6813.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://beaver6813.com</link>
	<description>Web Developer Extraordinaire!</description>
	<lastBuildDate>Thu, 05 Jan 2012 20:33:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19672</generator>
		<item>
		<title>[PHP] TLD List, Inc. Level 2 &amp; 3</title>
		<link>http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/</link>
		<comments>http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 16:48:19 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[All Level]]></category>
		<category><![CDATA[Automatic]]></category>
		<category><![CDATA[Levels 2 - 3]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[TLD List]]></category>
		<category><![CDATA[Top Level]]></category>
		<category><![CDATA[Updater]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=225</guid>
		<description><![CDATA[Whilst working on a new open-source project I needed to be able to be able to detect/remove the TLD&#8217;s from hostnames. This is no easy task algorithmically as example.co.uk (level 2) is just as valid as example.com (level 1) which &#8230; <a href="http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2010/04/htc-desire-release-dates/' rel='bookmark' title='HTC Desire Release Dates'>HTC Desire Release Dates</a></li>
<li><a href='http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/' rel='bookmark' title='MultiPart E-Mail Code for PHP (Text and HTML)'>MultiPart E-Mail Code for PHP (Text and HTML)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Whilst working on a new open-source project I needed to be able to be able to detect/remove the TLD&#8217;s from hostnames. This is no easy task algorithmically as example.co.uk (level 2) is just as valid as example.com (level 1) which is also just as valid as example.bob.shiga.jp (level 3). I came across a project from Mozilla that lists all TLDs. This isn&#8217;t the easiest format to work with each time you want to test hostnames. So I&#8217;ve built an auto-updater that will sort and serialize the domains into a format like:<br />
<span id="more-225"></span><br />
[uk] =&gt;</p>
<p style="padding-left: 30px;">*.uk</p>
<p style="padding-left: 30px;">!parliament.uk</p>
<p style="padding-left: 30px;">!nhs.uk</p>
<p>The updater then serializes the array for easy access via PHP at a later date. You may be wondering what the * and !&#8217;s mean. To put it simply it means that there could be anything just before the .uk and it should be counted as the domain such as .co.uk, .gov.uk. The ! before means that its an exception to the * (wildcard) rule, so in the case of parliament.uk, the parliament part should <strong>not</strong> be counted as part of the domain. A full explanation of this can be found at <a href="http://publicsuffix.org/format/" class="broken_link">http://publicsuffix.org/format/</a></p>
<p>Please find below the actual code for the updater. I decided against just posting the serialized list as the list will change over time where as this post may not.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2252"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code" id="p225code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//TLD List Updater (Formats to Serialized PHP)</span>
<span style="color: #666666; font-style: italic;">//Created by Beaver6813 (Beaver6813.com). Big thanks to the Mozilla community!</span>
<span style="color: #000088;">$tldlist</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$toplist</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tldlist</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr_count"><span style="color: #990000;">substr_count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;//&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">&amp;&amp;!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr_count"><span style="color: #990000;">substr_count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$sublist</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$dotxplode</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$dotxplode</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_reverse"><span style="color: #990000;">array_reverse</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dotxplode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sublist</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$dotxplode</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<a href="http://www.php.net/file_put_contents"><span style="color: #990000;">file_put_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;effective_tld_sublist.dat&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sublist</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2010/04/htc-desire-release-dates/' rel='bookmark' title='HTC Desire Release Dates'>HTC Desire Release Dates</a></li>
<li><a href='http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/' rel='bookmark' title='MultiPart E-Mail Code for PHP (Text and HTML)'>MultiPart E-Mail Code for PHP (Text and HTML)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Decor Scene</title>
		<link>http://beaver6813.com/2010/05/decor-scene/</link>
		<comments>http://beaver6813.com/2010/05/decor-scene/#comments</comments>
		<pubDate>Fri, 21 May 2010 11:32:27 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[decor scene]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[DIY store]]></category>
		<category><![CDATA[elegant]]></category>
		<category><![CDATA[family run]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=211</guid>
		<description><![CDATA[Decor Scene was a smaller, simpler project I worked on. Mike from Decor Scene tasked me with creating a simple, user-friendly website that gave Decor Scene, a family run DIY store, a web presence. For the main design I approached &#8230; <a href="http://beaver6813.com/2010/05/decor-scene/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2010/03/city-coupons/' rel='bookmark' title='City Coupons'>City Coupons</a></li>
<li><a href='http://beaver6813.com/2010/03/jokepants/' rel='bookmark' title='Jokepants'>Jokepants</a></li>
<li><a href='http://beaver6813.com/2010/09/amersham-dec/' rel='bookmark' title='Amersham Dec'>Amersham Dec</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src='http://beaver6813.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/211.png&amp;w=200&amp;h=150&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>Decor Scene was a smaller, simpler project I worked on. Mike from <a href="http://www.decorscene.co.uk">Decor Scene</a> tasked me with creating a simple, user-friendly website that gave <a href="http://www.decorscene.co.uk">Decor Scene</a>, a family run DIY store, a web presence. For the main design I approached a company I had recently worked with <a href="http://beaver6813.com/2010/03/jokepants/">Webslash</a> to design a simple, elegant and modern website that made an impact on any user who visited. After a few drafts we were there and it was down to me to slice the design and code it. As the site itself i<span id="more-211"></span>s rather simple I wanted to use the most efficient methods available and so split the website into three parts:</p>
<ul>
<li>Header &#8211; Template</li>
<li>Content &#8211; Custom for each page</li>
<li>Footer &#8211; Template</li>
</ul>
<p>By making the header and footer both templates it saved greatly on development times and served to make the website easier to update in the future.</p>
<p>A problem I encountered with this however arrived when it came to adding Google Maps to make it easier for potential customers to find the shop. Google Maps code is usually added to the head parts of the HTML and then an onload function is added to the body, so when the body is fully loaded Google Maps loads. It would be very inefficient to include the code on each page and could potentially generate errors so I simply included a check to see if it exists. I could then create this function just on the &#8220;Find Us&#8221; page and then use a small bit of javascript that checks if &#8220;runjavascript()&#8221; is defined, if it is, it runs it:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p211code4'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2114"><td class="code" id="p211code4"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> window.<span style="color: #660066;">runjavascript</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
runjavascript<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I think this is the more efficient or at least simplest way to do this, if anyone has a better way then let me know!</p>
<p>Some SEO work was also done on the website to ensure it hit page 1 on Google on some terms such as &#8220;DIY Store Rickmansworth&#8221;, &#8220;Decor Scene&#8221;, &#8220;Decor Scene Rickmansworth&#8221;, &#8220;DIY Shop Rickmansworth&#8221;; part of this was adding the business to Google Maps which benefits both customers and the business.</p>
<p>On final presentation to the client the response was very positive and whilst the website is fairly simple at the moment it certainly has left room for expansion in the future!</p>

<a href='http://beaver6813.com/2010/05/decor-scene/decorscene-home/' title='Decor Scene - Homepage'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/05/DecorScene-Home-150x150.png" class="attachment-thumbnail" alt="Decor Scene Homepage" title="Decor Scene - Homepage" /></a>
<a href='http://beaver6813.com/2010/05/decor-scene/decorscene-about/' title='Decor Scene - About Us'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/05/DecorScene-About-150x150.png" class="attachment-thumbnail" alt="Decor Scene - About Us" title="Decor Scene - About Us" /></a>
<a href='http://beaver6813.com/2010/05/decor-scene/decorscene-products/' title='Decor Scene - Products'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/05/DecorScene-Products-150x150.png" class="attachment-thumbnail" alt="Decor Scene - Products" title="Decor Scene - Products" /></a>
<a href='http://beaver6813.com/2010/05/decor-scene/decorscene-findus/' title='Decor Scene - Find Us'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/05/DecorScene-Findus-150x150.png" class="attachment-thumbnail" alt="Decor Scene - Find Us" title="Decor Scene - Find Us" /></a>

<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2010/03/city-coupons/' rel='bookmark' title='City Coupons'>City Coupons</a></li>
<li><a href='http://beaver6813.com/2010/03/jokepants/' rel='bookmark' title='Jokepants'>Jokepants</a></li>
<li><a href='http://beaver6813.com/2010/09/amersham-dec/' rel='bookmark' title='Amersham Dec'>Amersham Dec</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2010/05/decor-scene/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Search and Replace Directory Recursively</title>
		<link>http://beaver6813.com/2010/04/php-search-and-replace-directory-recursively/</link>
		<comments>http://beaver6813.com/2010/04/php-search-and-replace-directory-recursively/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 16:04:11 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[find and replace]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[recurse]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[search and replace]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=207</guid>
		<description><![CDATA[On a message forum I regularily visit a member was having issues with code being placed in multiple files that he wanted to remove or change without having to edit each and every file manually. For this I created a &#8230; <a href="http://beaver6813.com/2010/04/php-search-and-replace-directory-recursively/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2009/10/bash-bad-interpreter/' rel='bookmark' title='Bash, Bad Interpreter'>Bash, Bad Interpreter</a></li>
<li><a href='http://beaver6813.com/2010/03/godaddy-mod_rewrite-hell/' rel='bookmark' title='GoDaddy mod_rewrite Hell'>GoDaddy mod_rewrite Hell</a></li>
<li><a href='http://beaver6813.com/2009/10/fetchmp3-com/' rel='bookmark' title='FetchMP3.com'>FetchMP3.com</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>On a message forum I regularily visit a member was having issues with code being placed in multiple files that he wanted to remove or change without having to edit each and every file manually. For this I created a search and replace function which will recursively search the directory and every file<span id="more-207"></span> for a specific piece of code and will replace with whatever:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p207code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2076"><td class="code" id="p207code6"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span>?php
<span style="color: #000088;">$stringsearch</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;texttosearchfor&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stringreplace</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;texttoreplacewith&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;./&quot;</span><span style="color: #339933;">;</span>
SearchandReplace<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">,</span><span style="color: #000088;">$stringsearch</span><span style="color: #339933;">,</span><span style="color: #000088;">$stringreplace</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> SearchandReplace<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stringsearch</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stringreplace</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Starting search for <span style="color: #006699; font-weight: bold;">$stringsearch</span> within directory <span style="color: #006699; font-weight: bold;">$dir</span>
&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$listDir</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handler</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/opendir"><span style="color: #990000;">opendir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sub</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/readdir"><span style="color: #990000;">readdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handler</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sub</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$sub</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;..&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$sub</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;Thumb.db&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_file"><span style="color: #990000;">is_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr_count"><span style="color: #990000;">substr_count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sub</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.php'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                            <span style="color: #009900;">&#123;</span>
                            <span style="color: #000088;">$getfilecontents</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr_count"><span style="color: #990000;">substr_count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$getfilecontents</span><span style="color: #339933;">,</span><span style="color: #000088;">$stringsearch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
                            <span style="color: #009900;">&#123;</span>
                            <span style="color: #000088;">$replacer</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stringsearch</span><span style="color: #339933;">,</span><span style="color: #000088;">$stringreplace</span><span style="color: #339933;">,</span><span style="color: #000088;">$getfilecontents</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #666666; font-style: italic;">// Let's make sure the file exists and is writable first.</span>
                              <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_writable"><span style="color: #990000;">is_writable</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                       <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Cannot open file (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
                                       <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span>
                                  <span style="color: #009900;">&#125;</span>
                                  <span style="color: #666666; font-style: italic;">// Write $somecontent to our opened file.</span>
                                  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$replacer</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Cannot write to file (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
                                      <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span>
                                  <span style="color: #009900;">&#125;</span>
                                  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Success, removed searched content from:&quot;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;
&quot;</span><span style="color: #339933;">;</span>
                                  <a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                              <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                                  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The file &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #0000ff;">&quot; is not writable
&quot;</span><span style="color: #339933;">;</span>
                              <span style="color: #009900;">&#125;</span>
                            <span style="color: #009900;">&#125;</span>
                            <span style="color: #009900;">&#125;</span>
                        <span style="color: #000088;">$listDir</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sub</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color: #990000;">is_dir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000088;">$listDir</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$sub</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> SearchandReplace<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$sub</span><span style="color: #339933;">,</span><span style="color: #000088;">$stringsearch</span><span style="color: #339933;">,</span><span style="color: #000088;">$stringreplace</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <a href="http://www.php.net/closedir"><span style="color: #990000;">closedir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$listDir</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">--&gt;</span></pre></td></tr></table></div>

<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2009/10/bash-bad-interpreter/' rel='bookmark' title='Bash, Bad Interpreter'>Bash, Bad Interpreter</a></li>
<li><a href='http://beaver6813.com/2010/03/godaddy-mod_rewrite-hell/' rel='bookmark' title='GoDaddy mod_rewrite Hell'>GoDaddy mod_rewrite Hell</a></li>
<li><a href='http://beaver6813.com/2009/10/fetchmp3-com/' rel='bookmark' title='FetchMP3.com'>FetchMP3.com</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2010/04/php-search-and-replace-directory-recursively/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jokepants</title>
		<link>http://beaver6813.com/2010/03/jokepants/</link>
		<comments>http://beaver6813.com/2010/03/jokepants/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 14:53:34 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[fmyscript]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[joke site]]></category>
		<category><![CDATA[jokepants]]></category>
		<category><![CDATA[photoshop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[psd]]></category>
		<category><![CDATA[SMARTY]]></category>
		<category><![CDATA[webslash]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=164</guid>
		<description><![CDATA[Web development firm Webslash approached me with the task of integrating their design for a new joke sharing website, Jokepants, into an existing script called FMyScript. FMyScript is a story sharing script. This was a relatively quick project as the &#8230; <a href="http://beaver6813.com/2010/03/jokepants/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2010/05/decor-scene/' rel='bookmark' title='Decor Scene'>Decor Scene</a></li>
<li><a href='http://beaver6813.com/2009/10/php-get-current-time-in-milliseconds/' rel='bookmark' title='[PHP] Get current time in milliseconds'>[PHP] Get current time in milliseconds</a></li>
<li><a href='http://beaver6813.com/2009/10/about-me/' rel='bookmark' title='About Me'>About Me</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src='http://beaver6813.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/164.png&amp;w=200&amp;h=150&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>Web development firm <a href="http://www.webslash.be">Webslash</a> approached me with the task of integrating their design for a new joke sharing website, Jokepants, into an existing script called <a href="http://www.fmyscript.com/">FMyScript</a>. <a href="http://www.fmyscript.com/">FMyScript</a> is a story sharing script. This was a relatively quick project as the script was already coded and just required modifications to make it suitable for jokes as opposed to stories.<span id="more-164"></span></p>
<p>After I had sliced and programmed the design into wc3 valid XHTML and CSS it was simply a task of splitting the page into the seperate parts required for FMyScript&#8217;s <a href="http://www.smarty.net/">SMARTY</a> templating engine, i.e. header, footer, sidebar and content boxes.</p>
<p>After the base design was in place some minor definitions in the script had to be modified and a few bugs had to be fixed in the actual script. After this was complete Jokepants was ready for launch!</p>

<a href='http://beaver6813.com/2010/03/jokepants/jokepantshome/' title='Jokepants Homepage'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/JokepantsHome-150x150.png" class="attachment-thumbnail" alt="Jokepants Homepage" title="Jokepants Homepage" /></a>
<a href='http://beaver6813.com/2010/03/jokepants/jokepantspage/' title='Jokepants Content Page'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/JokepantsPage-150x150.png" class="attachment-thumbnail" alt="Jokepants Content Page" title="Jokepants Content Page" /></a>
<a href='http://beaver6813.com/2010/03/jokepants/indev2/' title='Jokepants in Development'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/indev2-150x150.png" class="attachment-thumbnail" alt="Jokepants in Development" title="Jokepants in Development" /></a>
<a href='http://beaver6813.com/2010/03/jokepants/indev/' title='Jokepants in Development'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/indev-150x150.png" class="attachment-thumbnail" alt="Jokepants in Development" title="Jokepants in Development" /></a>

<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2010/05/decor-scene/' rel='bookmark' title='Decor Scene'>Decor Scene</a></li>
<li><a href='http://beaver6813.com/2009/10/php-get-current-time-in-milliseconds/' rel='bookmark' title='[PHP] Get current time in milliseconds'>[PHP] Get current time in milliseconds</a></li>
<li><a href='http://beaver6813.com/2009/10/about-me/' rel='bookmark' title='About Me'>About Me</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2010/03/jokepants/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>City Coupons</title>
		<link>http://beaver6813.com/2010/03/city-coupons/</link>
		<comments>http://beaver6813.com/2010/03/city-coupons/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 19:24:06 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[city coupons]]></category>
		<category><![CDATA[citycoupons]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[content management]]></category>
		<category><![CDATA[coupons]]></category>
		<category><![CDATA[email to sms]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[paypal IPN]]></category>
		<category><![CDATA[pdf generation]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[printable coupons]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[sms coupons]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=146</guid>
		<description><![CDATA[City Coupons, a very recent project, in essence is a full content management for coupons. Using the system you are able to add printable, SMS and viewable coupons to your website. In addition to this, the system has a range &#8230; <a href="http://beaver6813.com/2010/03/city-coupons/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2010/05/decor-scene/' rel='bookmark' title='Decor Scene'>Decor Scene</a></li>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2009/10/fetchmp3-com/' rel='bookmark' title='FetchMP3.com'>FetchMP3.com</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src='http://beaver6813.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/146.png&amp;w=200&amp;h=150&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>City Coupons, a very recent project, in essence is a full content management for coupons. Using the system you are able to add printable, SMS and viewable coupons to your website. In addition to this, the system has a range of other features to offer. Started at the beginning of November &#8217;09 and completed with version 1.0.2 in February &#8217;10 its certainly been a large but exciting project.</p>
<p><span id="more-146"></span></p>
<h3>Startup</h3>
<p>In November I was asked to create a piece of coupon management software that would:</p>
<ul>
<li>Allow businesses to sign up and pay automatically.</li>
<li>Enable businesses to manage their business profiles on the site, including locations, media, descriptions and above all coupons &amp; offers.</li>
<li>Give the site administrator full control over the site in the simplest way possible.</li>
<li>To incorporate some sort of events calendar into the site that would gather all invidual business events.</li>
</ul>
<p>We started with a basic design which was heavily edited to fit with the feel of the site. I then started work on coding the back-end into classes (object orientated) to make upgrading and modifying the site a lot more modular.</p>
<h3>Payment System</h3>
<p>The site is integrated with the PayPal IPN payment processing which will, after a business has gone through checkout, notify the site and will automatically activate their account. In addition to this it also has an automated billing program that will periodically check to ensure that all businesses are up to date on their payments. If not it will send the business an invoice with three days grace period. After that their account will be suspended until they activate their account. Of course this can always be overridden in the site admin panel.</p>
<h3>Business Page &amp; Coupons</h3>
<p>An important aspect of the site was enabling businesses to have their own &#8220;online presence&#8221;, this was achieved by giving each business their own profile page in addition to their various offers appearing site-wide. On this page businesses can display all of their locations alongside Google Maps, uploaded media, events and other exciting items.</p>
<p>Having a list of offers on the website may not be much use to a lot of people, City Coupons enables users to print and send the offer to their cell phone. The printing system used is major improvement over the type used on similar coupon websites. It enables you to specify the quantity of the coupon you wish to print and even place different coupons on the same page if you bookmark them. The SMS service has no operating costs and uses data processing techniques specific to each major carrier in the US.</p>
<h3>Administering the Site</h3>
<p>In the Vendor Admin Panel (for businesses) you are able to easily modify any aspect of your profile through the various tabs on the page conveniently titled, Offers, Locations, Events, Media, Profile etc. Likewise the Site Admin Panel is arranged similarly but with a wide range of options from full user management to bulk newsletter services and footer modifications.</p>
<p>To make the system even more interactive; it is integrated with the WordPress blog system to provide the blogging and article aspects of the site. WordPress is one of the best systems in the world for this and it would be senseless to reinvent the wheel. It however does include several City Coupons themes and plugins for full integration with the member system and site design.</p>
<p>The default site design is easily customizable and is available in a variety of colours, some different colours used by current owners of the system are shown in the thumbnails below.</p>
<h3>Conclusion</h3>
<p>Overall the City Coupons project was great fun and as always I developed my programming skills. My knowledge of WordPress has been greatly improved, my coding standards have risen significantly and I now know how to generate PDF&#8217;s from pure PHP! The client had a firm vision of what the site should be like and it certainly helped me to create exactly what he envisioned.</p>

<a href='http://beaver6813.com/2010/03/city-coupons/defaultgreen/' title='Main Site Default Theme'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/DefaultGreen-150x150.png" class="attachment-thumbnail" alt="Main Site Default Theme" title="Main Site Default Theme" /></a>
<a href='http://beaver6813.com/2010/03/city-coupons/homecontent/' title='Business Page '><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/HomeContent-150x150.png" class="attachment-thumbnail" alt="Business Page" title="Business Page" /></a>
<a href='http://beaver6813.com/2010/03/city-coupons/vendoradminpanel/' title='Vendor Admin Panel'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/VendorAdminPanel-150x150.png" class="attachment-thumbnail" alt="Vendor Admin Panel" title="Vendor Admin Panel" /></a>
<a href='http://beaver6813.com/2010/03/city-coupons/siteadminpanel/' title='Site Admin Panel'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/SiteAdminPanel-150x150.png" class="attachment-thumbnail" alt="Site Admin Panel" title="Site Admin Panel" /></a>
<a href='http://beaver6813.com/2010/03/city-coupons/lacoupons/' title='Blue on LA Coupons'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/LaCoupons-150x150.png" class="attachment-thumbnail" alt="Blue on LA Coupons" title="Blue on LA Coupons" /></a>
<a href='http://beaver6813.com/2010/03/city-coupons/austincoupons/' title='Orange/Bronze on Austin Coupons'><img width="150" height="150" src="http://beaver6813.com/wp-content/uploads/2010/03/AustinCoupons-150x150.png" class="attachment-thumbnail" alt="Orange/Bronze on Austin Coupons" title="Orange/Bronze on Austin Coupons" /></a>

<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2010/05/decor-scene/' rel='bookmark' title='Decor Scene'>Decor Scene</a></li>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2009/10/fetchmp3-com/' rel='bookmark' title='FetchMP3.com'>FetchMP3.com</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2010/03/city-coupons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MultiPart E-Mail Code for PHP (Text and HTML)</title>
		<link>http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/</link>
		<comments>http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 15:53:26 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[compatability]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mime]]></category>
		<category><![CDATA[multipart]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[updated]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=88</guid>
		<description><![CDATA[Whilst trawling through some of my ultra-old posts on various forums I&#8217;ve found this nifty little piece of code that enables you to send in both HTML and TEXT form. This is useful for clients that cant display HTML (they &#8230; <a href="http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2010/03/godaddy-mod_rewrite-hell/' rel='bookmark' title='GoDaddy mod_rewrite Hell'>GoDaddy mod_rewrite Hell</a></li>
<li><a href='http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/' rel='bookmark' title='[PHP] TLD List, Inc. Level 2 &amp; 3'>[PHP] TLD List, Inc. Level 2 &#038; 3</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Whilst trawling through some of my ultra-old posts on various forums I&#8217;ve found this nifty little piece of code that enables you to send in both HTML and TEXT form. This is useful for clients that cant display HTML (they will display the text instead). I developed it back in 2007 so it may need updating but its a useful bit of code!<br />
<em>UPDATE: Peter Mills recently emailed me with a problem with this script and compatability with gmail, I have managed to fix this. It seems that gmails parser has gotten even more strict, there were stray line breaks where there shouldnt have been and the initial boundary declaration in the headers was not wrapped properly in double quotes! Cheers for finding this bug Peter and hopefully its all working again now!</em><br/></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p88code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p888"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
</pre></td><td class="code" id="p88code8"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Sam Cleaver aka Beaver6813 (http://www.beaver6813.com)
Mutlipart Email Script, Sends In Both Plain And HTML For Compatibility
Which Works With MIME 1.0+ Supporting Software.
Email: samcleaver.beaver[-at]gmail[-dot]com
Copyright (C) 2007  Beaver6813
Updated November 2009. Thanks to Peter Mills for his help in recognising
the recent problem the script had with GMail!
--------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
--------------------------------------------------------------
*/</span>
<span style="color: #666666; font-style: italic;">/*
 CHANGES:
 -- Is Now Compatible With GMail
 -- Encrypts Messages In Base64 For Easier Transportation
 -- 03/11/09 - Changed to work with changes in GMail, removed now unnecessary base64 encoding
 NOTES:
 -- From experience with different mail services i've discovered some key pointers
 when sending html or any type of email:
  * DO NOT link to external CSS stylesheets, most of the time these are either filtered out
  or do not load properly
  * As discovered in GMail it strips out any stylesheets completely, even inline ones so you're
  going to have to use the style='' tags on any div's etc you want to make look pretty
  * Bear in mind linking to any external resources will bring up a warning on the clients
  end and they can choose to or not to load external resources.
  * Keep HTML resources as simple as possible, most of the time they aren't loaded as well as
  they would in firefox and so can be really mucked up if you do some complicated magic with
  them.
 COMING SOON:
 -- Will be turned into a class making it easier to send emails :)
*/</span>
<span style="color: #666666; font-style: italic;"># Is the OS Windows or Mac or Linux
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/strtoupper"><span style="color: #990000;">strtoupper</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">PHP_OS</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'WIN'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$eol</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/strtoupper"><span style="color: #990000;">strtoupper</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">PHP_OS</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'MAC'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$eol</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$eol</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$_emailer_subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;My First Email Yay!&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The subject of the email... duh</span>
<span style="color: #000088;">$_emailer_to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sam@beaver6813.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//You can make this even easier for the</span>
 <span style="color: #666666; font-style: italic;">//email client by specifying the actual name of the person as well, but for</span>
 <span style="color: #666666; font-style: italic;">//simplicities sake we'll just give the email</span>
<span style="color: #000088;">$_emailer_from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;test@localhost&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Again, you can do to this what</span>
<span style="color: #666666; font-style: italic;">//i said above</span>
<span style="color: #000088;">$_emailer_reply_to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;test@localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_emailer_cc</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Optional</span>
<span style="color: #000088;">$_emailer_bcc</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//Optional</span>
<span style="color: #666666; font-style: italic;">//Okay what do you want to appear if it displays the plain text version?</span>
<span style="color: #000088;">$email_html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;HTML E-mail&lt;/h1&gt;
&lt;p&gt;This is an &lt;b&gt;HTML&lt;/b&gt; e-mail.&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Okay what do you want to appear if it displays the HTML version?</span>
<span style="color: #000088;">$email_plain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;HTML E-mail<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>This is the text portion of an HTML e-mail<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* YOU NEED CONFIGURE NOTHING MORE!!!! (Apart from the respond at the very bottom of this script!) */</span>
<span style="color: #000088;">$_emailer_subject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_emailer_subject</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span> ? <span style="color: #0000ff;">'No Subject'</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_emailer_subject</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Must have a subject</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_emailer_cc</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$_emailer_cc_do</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Cc: &quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_emailer_cc</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Remove the trailing &quot;, &quot;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_emailer_bcc</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$_emailer_bcc_do</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bcc: &quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_emailer_bcc</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_emailer_reply_to</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_emailer_reply_to</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span> ? <span style="color: #000088;">$_emailer_from</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_emailer_reply_to</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mid</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/md5"><span style="color: #990000;">md5</span></a><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/uniqid"><span style="color: #990000;">uniqid</span></a><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Generate a unique id for the email</span>
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'www'</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Remove the www for an &quot;email address&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//add From: header</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: <span style="color: #006699; font-weight: bold;">$_emailer_from</span><span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//specify MIME version 1.0</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Return-Path: <span style="color: #006699; font-weight: bold;">$_emailer_reply_to</span><span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$_emailer_cc_do</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$_emailer_bcc_do</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;MIME-Version: 1.0<span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Message-ID: &lt;<span style="color: #006699; font-weight: bold;">$mid</span>@<span style="color: #006699; font-weight: bold;">$host</span>&gt;<span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;X-Priority: 3<span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;X-MSMail-Priority: Normal<span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;X-Mailer: PHP<span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;X-MimeOLE: Generated By Beaver6813s MultiPart Mail Script<span style="color: #006699; font-weight: bold;">$eol</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Date: &quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/gmdate"><span style="color: #990000;">gmdate</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s Z'</span> <span style="color: #339933;">,</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//unique boundary this can be whatever you want... but try and make it imaginative :)</span>
<span style="color: #000088;">$boundary</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/uniqid"><span style="color: #990000;">uniqid</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BEAVER6813&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//tell e-mail client this e-mail contains//alternate versions</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Content-type: multipart/alternative; boundary=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$boundary</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//plain text version of message</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--<span style="color: #006699; font-weight: bold;">$boundary</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Type: text/plain; charset=<span style="color: #000099; font-weight: bold;">\&quot;</span>iso-8859-1<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-transfer-encoding: 8bit&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/chunk_split"><span style="color: #990000;">chunk_split</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$email_plain</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//HTML version of message</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;--<span style="color: #006699; font-weight: bold;">$boundary</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Type: text/html; charset=<span style="color: #000099; font-weight: bold;">\&quot;</span>iso-8859-1<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Transfer-Encoding: quoted-printable&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/chunk_split"><span style="color: #990000;">chunk_split</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$email_html</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># Finished
</span><span style="color: #000088;">$body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;--<span style="color: #006699; font-weight: bold;">$boundary</span>--&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">.</span><span style="color: #000088;">$eol</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// finish with two eol's for better security.</span>
<span style="color: #666666; font-style: italic;">//send message</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mail"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_emailer_to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_emailer_subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;MAIL SENT SUCCESSFULLY. YOU'RE A WINNER!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;SOME WEIRD ERROR :S. YOU LOSE&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2010/03/godaddy-mod_rewrite-hell/' rel='bookmark' title='GoDaddy mod_rewrite Hell'>GoDaddy mod_rewrite Hell</a></li>
<li><a href='http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/' rel='bookmark' title='[PHP] TLD List, Inc. Level 2 &amp; 3'>[PHP] TLD List, Inc. Level 2 &#038; 3</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>[PHP] Get current time in milliseconds</title>
		<link>http://beaver6813.com/2009/10/php-get-current-time-in-milliseconds/</link>
		<comments>http://beaver6813.com/2009/10/php-get-current-time-in-milliseconds/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 17:59:31 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[milliseconds]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=100</guid>
		<description><![CDATA[I recently needed to get the current time in milliseconds, of course this can easily be retrieved using microtime() however I needed the entire number in digits, not in decimals with seconds seperately etc. Heres how: View Code PHP1 2 &#8230; <a href="http://beaver6813.com/2009/10/php-get-current-time-in-milliseconds/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2010/04/php-search-and-replace-directory-recursively/' rel='bookmark' title='PHP Search and Replace Directory Recursively'>PHP Search and Replace Directory Recursively</a></li>
<li><a href='http://beaver6813.com/2010/03/jokepants/' rel='bookmark' title='Jokepants'>Jokepants</a></li>
<li><a href='http://beaver6813.com/2010/05/decor-scene/' rel='bookmark' title='Decor Scene'>Decor Scene</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I recently needed to get the current time in milliseconds, of course this can easily be retrieved using microtime() however I needed the entire number in digits, not in decimals with seconds seperately etc. Heres how:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10010"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p100code10"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$timeparts</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/microtime"><span style="color: #990000;">microtime</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$currenttime</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/bcadd"><span style="color: #990000;">bcadd</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><a href="http://www.php.net/bcmul"><span style="color: #990000;">bcmul</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$currenttime</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><em>NOTE: PHP5 is required for this function due to the improvements with microtime() and the bc math module is also required (as we&#8217;re dealing with large numbers, you can check if you have the module in phpinfo).</em></p>
<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2010/04/php-search-and-replace-directory-recursively/' rel='bookmark' title='PHP Search and Replace Directory Recursively'>PHP Search and Replace Directory Recursively</a></li>
<li><a href='http://beaver6813.com/2010/03/jokepants/' rel='bookmark' title='Jokepants'>Jokepants</a></li>
<li><a href='http://beaver6813.com/2010/05/decor-scene/' rel='bookmark' title='Decor Scene'>Decor Scene</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2009/10/php-get-current-time-in-milliseconds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

