<?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>Alan Whipple</title>
	<atom:link href="http://alanwhipple.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://alanwhipple.com</link>
	<description>Alan Whipple is a motivated Web Developer / Programmer with proficiency in PHP, JavaScript, Ajax, HTML, CSS, MySQL, Apache, SVN, jQuery, WordPress.</description>
	<lastBuildDate>Fri, 10 Jun 2011 16:44:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Algae will replace petroleum with biodiesel, biogasoline, and even plastic</title>
		<link>http://alanwhipple.com/2011/06/08/algae-replace-petroleum-biodiesel-biogasoline-plastic/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=algae-replace-petroleum-biodiesel-biogasoline-plastic</link>
		<comments>http://alanwhipple.com/2011/06/08/algae-replace-petroleum-biodiesel-biogasoline-plastic/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 16:19:40 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[Energy]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=21</guid>
		<description><![CDATA[I am amazed by algae to the point that I am convinced it can almost completely replace petroleum (the raw fossil fuel commonly referred to as &#8220;oil&#8221;). Here are some important products that can be derived from processing petroleum OR algae: Gasoline (biogasoline) Diesel fuel (biodiesel) Jet fuel (aviation biofuel) Plastics (bioplastic) And yes, the [...]]]></description>
			<content:encoded><![CDATA[<p>I am amazed by algae to the point that I am convinced it can almost completely replace petroleum (the raw fossil fuel commonly referred to as &#8220;oil&#8221;).</p>
<p>Here are some important products that can be derived from processing petroleum OR algae:</p>
<ul>
<li>Gasoline (<a href="http://en.wikipedia.org/wiki/Biogasoline">biogasoline</a>)</li>
<li>Diesel fuel (<a href="http://en.wikipedia.org/wiki/Biodiesel">biodiesel</a>)</li>
<li>Jet fuel (<a href="http://en.wikipedia.org/wiki/Aviation_biofuel">aviation biofuel</a>)</li>
<li>Plastics (<a href="http://en.wikipedia.org/wiki/Bioplastic">bioplastic</a>)</li>
</ul>
<p>And yes, the <a href="http://en.wikipedia.org/wiki/Algal_fuel">algae-based fuels</a> (and <a href="http://www.celsias.com/article/cereplast-algae-plastic/">plastics</a>) work just as well as the petroleum-based fuels, and can be used in existing engines without any modification. Engines will run the same and burn cleaner (although they still emit CO2).</p>
<p>Of course algae and petroleum aren&#8217;t exactly the same. Petroleum can be processed to get: tar, asphalt, and pesticides. Algae can be processed to get: nutrients, animal feed, and vegetable oil.</p>
<p>Biofuels (like biodiesel) can be produced from any <a href="http://en.wikipedia.org/wiki/Biomass">biomass</a> (like corn, soy, or even wood chips). However, the efficiency (in terms of oil yield per acre) of algae is astronomical compared any other feedstock.</p>
<div id="attachment_9" class="wp-caption aligncenter" style="width: 660px"><img src="http://alanwhipple.com/wp-content/uploads/2011/06/biomass-algae-graph-650x444.jpg" alt="" title="biomass-algae-graph" width="650" height="444" class="size-large wp-image-9" /><p class="wp-caption-text">Graphic I stole from: <a href='http://www.energyandcapital.com/articles/biofuel-algae-biodiesel/395'>http://www.energyandcapital.com/articles/biofuel-algae-biodiesel/395</a></p></div>
<p>Algae:</p>
<ul>
<li>naturally takes CO2 out of the atmosphere and releases oxygen (while alive)</li>
<li>grows very fast (harvest cycle of 1–10 days)</li>
<li>does not require fresh water (seawater and wastewater will do)</li>
<li>does not require quality farm land (dry or saline soil will do)</li>
<li>actually thrives off wastewater (found at a wastewater treatment facility, post-bacteria)</li>
<li>also thrives by consuming CO2 emissions directly from factories and power plants</li>
</ul>
<p>Algae farms can easily have symbiotic (mutually beneficial) relationship with cement factories, coal power plants, wastewater treatment facilities, or any other facility that produces CO2 emissions. For example, CO2 emissions are normally an unwanted bi-product. However, pumping the CO2 through algae will reduce the emissions and feed the algae growth leading to faster oil production. </p>
<p>Properly produced biofuels can be used in existing engines without modification. You&#8217;d have to modify a diesel engine to run on vegetable oil, yes, but it can be done. However, biodiesel is essentially the same as &#8220;petrodiesel&#8221; and can be used as a drop in replacement. To quote an article:</p>
<blockquote><p>
These biofuels, which some refer to as &#8220;renewable petroleum,&#8221; will be designed with the same properties of hydrocarbons that now fuel our vehicles, but be made from biomass, rather than petroleum. </p>
<p>Custom-designed synthetic fuels are very appealing to established fossil fuel providers because, unlike ethanol, they should not require significant changes to the existing fuel infrastructure, said Nathanael Greene, a biofuels policy analyst at the National Resource Defense Council (NRDC). </p>
<p><a href="http://news.cnet.com/8301-11128_3-9849832-54.html">http://news.cnet.com/8301-11128_3-9849832-54.html</a>
</p></blockquote>
<p>Plastic can also be derived from algae (as opposed to petroleum). See:<br />
<a href="http://www.celsias.com/article/cereplast-algae-plastic/">http://www.celsias.com/article/cereplast-algae-plastic/</a><br />
<a href="http://en.wikipedia.org/wiki/Bioplastic">http://en.wikipedia.org/wiki/Bioplastic</a></p>
<h3>Videos</h3>
<p>A couple of algae based companies have decent YouTube videos promoting their work.</p>
<p>PetroAlgae</p>
<p><object width="650" height="391"><param name="movie" value="http://www.youtube.com/v/e-RyKyvWr3I?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/e-RyKyvWr3I?version=3" type="application/x-shockwave-flash" width="650" height="391" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Valcent  / Vertigro</p>
<p><object width="650" height="513"><param name="movie" value="http://www.youtube.com/v/vxNeBQCRv1c?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/vxNeBQCRv1c?version=3" type="application/x-shockwave-flash" width="650" height="513" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h3>Investing</h3>
<p>I wish I could just invest in an index of all companies doing work with algae. However, no such index exists.  Additionally, many companies doing good work are still privately owned. They are competing and guarding their secrets; thus slowing down progress. However, in the end, we will all benefit from the good ol&#8217; American competition. </p>
<p>During my research, these companies stuck out:</p>
<ul>
<li><a href="http://www.petroalgae.com/">PetroAlgae</a> (PINK: PALG)</li>
<li><a href="http://www.originoil.com/">OriginOil</a> (OTC:OOIL)</li>
<li>Valcent / Vertigro (public, but confusing digital presence)</li>
<li><a href="http://en.wikipedia.org/wiki/PetroSun">PetroSun</a> (PINK:PSUD)</li>
<li><a href="http://www.cereplast.com/">Cereplast</a> (NASDAQ:CERP)</li>
<li><a href="http://www.solazyme.com/">Solazyme</a> (IPO coming soon!)</li>
<li><a href="http://www.sapphireenergy.com/">Sapphire Energy</a></li>
<li><a href="http://www.bioecotek.com/">BioEcoTek</a></li>
</ul>
<p>Many sites discussing the up-coming algae market and companies refer to <a href="http://gigaom.com/cleantech/15-algae-startups-bringing-pond-scum-to-fuel-tanks/">this list of 15 promising startups</a></p>
<p>For more on investing in green companies (including algae biofuels), check out:<br />
<a href="http://www.greenchipstocks.com/">http://www.greenchipstocks.com/</a><br />
<a href="http://greenworldinvestor.com/">http://greenworldinvestor.com/</a></p>
<p>For general news and information on the algae industry, check out:<br />
<a href="http://www.oilgae.com/">http://www.oilgae.com/</a><br />
<a href="http://www.algalbiomass.org/">http://www.algalbiomass.org/</a><br />
<a href="http://www.algaeindustrymagazine.com/">http://www.algaeindustrymagazine.com/</a></p>
<p>More Wikipedia pages:<br />
<a href="http://en.wikipedia.org/wiki/List_of_algal_fuel_producers">List of algal fuel producers</a><br />
<a href="http://en.wikipedia.org/wiki/List_of_biofuel_companies_and_researchers">List of biofuel companies and researchers</a> </p>
<h3>Cost and Timeline</h3>
<p>Currently it&#8217;s cheaper to drill for petroleum. However, petroleum is a limited resource and prices are always going up. Meanwhile, technology surrounding harvesting and processing algae for biofuels and other products keeps getting better and cheaper. It&#8217;s only a matter of time before those 2 lines cross on the graph.</p>
<p>Obama supports domestic biofuels. If the government started officially endorsing (probably via tax credits) biofuels, and stopped supporting &#8220;petrofuels&#8221;, I am confident that we would be able to make the switch from fossil fuels to renewable fuels (for the vast majority of its applications).</p>
<p>This market is just waiting to explode. In the future, vehicles may have engines that work in completely different ways. For example, the hydrogen fuel cell, which powers electric cars and only releases water as the bi-product. However, for the time being, we have to deal with the millions of vehicles and engines that already exist. The intermediate step will be to replace the FUEL.</p>
]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2011/06/08/algae-replace-petroleum-biodiesel-biogasoline-plastic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Clean encoding issues with smart (curly) quotes, em dashes and more</title>
		<link>http://alanwhipple.com/2011/06/04/php-clean-encoding-issues-smart-curly-quotes-em-dashes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-clean-encoding-issues-smart-curly-quotes-em-dashes</link>
		<comments>http://alanwhipple.com/2011/06/04/php-clean-encoding-issues-smart-curly-quotes-em-dashes/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 16:11:57 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=15</guid>
		<description><![CDATA[When dealing with content from various sources, such as XML feeds, you will inevitably encounter problems with smart quotes, em dashes, and other random encoding issues. Smart quotes are known by other names such as curly quotes and left/right angled quotes. The main problem is Windows. Many Windows programs use Windows-1252 character encoding, which is [...]]]></description>
			<content:encoded><![CDATA[<p>When dealing with content from various sources, such as XML feeds, you will inevitably encounter problems with smart quotes, em dashes, and other random encoding issues. Smart quotes are known by other names such as curly quotes and left/right angled quotes.</p>
<p>The main problem is Windows. Many Windows programs use <a href="http://en.wikipedia.org/wiki/Windows-1252">Windows-1252</a> character encoding, which is very similar to ISO-8859-1, but with some differences. Attempts to detect the encoding of a Windows-1252 string will tend to result in a guess of ISO-8859-1. So conversion tools will overlook the differences. Unfortunately,  there are some relatively common characters among the differences. These characters include left/right angled single/double quotes, em/en dashes, ellipsis, and bullets.</p>
<p>To deal with these encoding issues, I wrote a function to do the cleanup and convert the string to UTF-8.</p>
<p>Note: I have only tested this with the English language / character set.</p>
<p>Full disclosure: PHP must have the <strong>mbstring</strong> extension enabled to use the mb_* functions.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * cleanEncoding deals with pesky characters like curly smart quotes and em dashes (and some other encoding related problems)
 *
 * @param string $text Text string to cleanup / convert
 * @param string $type 'standard' for standard characters, 'reference' for decimal numerical character reference
 *
 * @return $text Cleaned up UTF-8 string
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> cleanEncoding<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'standard'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// determine the encoding before we touch it</span>
    <span style="color: #000088;">$encoding</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_detect_encoding</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8, ISO-8859-1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// The characters to output</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'standard'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$outp_chr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'...'</span><span style="color: #339933;">,</span>          <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span>            <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span>            <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span>            <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span>            <span style="color: #0000ff;">'•'</span><span style="color: #339933;">,</span>            <span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span>            <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// run of the mill standard characters</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'reference'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$outp_chr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;#8230;'</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">'&amp;#8216;'</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">'&amp;#8217;'</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">'&amp;#8220;'</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">'&amp;#8221;'</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">'&amp;#8226;'</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">'&amp;#8211;'</span><span style="color: #339933;">,</span>      <span style="color: #0000ff;">'&amp;#8212;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// decimal numerical character references</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// The characters to replace (purposely indented for comparison)</span>
        <span style="color: #000088;">$utf8_chr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\xa6</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x98</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x99</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x9c</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x9d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'\xe2\x80\xa2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x93</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x94</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// UTF-8 hex characters</span>
        <span style="color: #000088;">$winc_chr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">133</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>       <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">145</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>       <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">146</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>       <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">147</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>       <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">148</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>       <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">149</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>       <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>       <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">151</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;">// ASCII characters (found in Windows-1252)</span>
    <span style="color: #666666; font-style: italic;">// First, replace UTF-8 characters.</span>
    <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$utf8_chr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$outp_chr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Next, replace Windows-1252 characters.</span>
    <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$winc_chr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$outp_chr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// even if the string seems to be UTF-8, we can't trust it, so convert it to UTF-8 anyway</span>
    <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$encoding</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If you are interested in more information on this topic, here are some links you may find helpful:<br />
<a href="http://www.joelonsoftware.com/articles/Unicode.html">http://www.joelonsoftware.com/articles/Unicode.html</a><br />
<a href="http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php#comment-3">http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php#comment-3</a><br />
<a href="http://web.forret.com/tools/charmap.asp?show=ascii">http://web.forret.com/tools/charmap.asp?show=ascii</a><br />
<a href="http://en.wikipedia.org/wiki/Extended_ASCII">http://en.wikipedia.org/wiki/Extended_ASCII</a><br />
<a href="http://www.ascii-code.com/">http://www.ascii-code.com/</a><br />
<a href="http://stackoverflow.com/questions/631406/what-is-the-difference-between-em-dash-151-and-8212">http://stackoverflow.com/questions/631406/what-is-the-difference-between-em-dash-151-and-8212</a><br />
<a href="http://en.wikipedia.org/wiki/Numeric_character_reference">http://en.wikipedia.org/wiki/Numeric_character_reference</a><br />
<a href="http://www.dwheeler.com/essays/quotes-in-html.html">http://www.dwheeler.com/essays/quotes-in-html.html</a><br />
<a href="http://www.i18nguy.com/markup/ncrs.html">http://www.i18nguy.com/markup/ncrs.html</a><br />
<a href="http://www.kadifeli.com/fedon/utf.htm">http://www.kadifeli.com/fedon/utf.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2011/06/04/php-clean-encoding-issues-smart-curly-quotes-em-dashes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Truncate string while preserving HTML tags and whole words</title>
		<link>http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-truncate-string-preserving-html-tags-words</link>
		<comments>http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/#comments</comments>
		<pubDate>Wed, 25 May 2011 16:23:25 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=23</guid>
		<description><![CDATA[Truncating strings is a very common task while programming. Sometimes those strings have HTML code within them. If you simply truncated at X characters, you risk outputting very broken HTML. If you can live without the HTML, the easy solution is to strip_tags. However, if you want to preserve the HTML tags, you&#8217;ll need a [...]]]></description>
			<content:encoded><![CDATA[<p>Truncating strings is a very common task while programming. Sometimes those strings have HTML code within them. If you simply truncated at X characters, you risk outputting very broken HTML. If you can live without the HTML, the easy solution is to <a href="http://php.net/manual/en/function.strip-tags.php">strip_tags</a>. However, if you want to preserve the HTML tags, you&#8217;ll need a smarter truncate function.</p>
<p>I yanked this function from <a href="http://dodona.wordpress.com/2009/04/05/how-do-i-truncate-an-html-string-without-breaking-the-html-code/">a blog</a> who looks like they yanked it from <a href="http://www.gsdesign.ro/blog/cut-html-string-without-breaking-the-tags/">another blog</a>, who yanked in from the <a href="http://cakephp.org/">CakePHP</a> framework. This function is too good not to share.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags
 *
 * @param string $text String to truncate.
 * @param integer $length Length of returned string, including ellipsis.
 * @param string $ending Ending to be appended to the trimmed string.
 * @param boolean $exact If false, $text will not be cut mid-word
 * @param boolean $considerHtml If true, HTML tags would be handled correctly
 *
 * @return string Trimmed string.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> truncateHtml<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ending</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'...'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$exact</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$considerHtml</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</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;">$considerHtml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// if the plain text is shorter than the maximum length, return the whole text</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;.*?&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// splits all html-tags to scanable lines</span>
		<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(&lt;.+?&gt;)?([^&lt;&gt;]*)/s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lines</span><span style="color: #339933;">,</span> PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$total_length</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ending</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$open_tags</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$truncate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line_matchings</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// if there is any html-tag in this line, handle it and add it (uncounted) to the output</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line_matchings</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// if it's an &quot;empty element&quot; with or without xhtml-conform closing slash</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^&lt;(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)&gt;$/is'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line_matchings</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// do nothing</span>
				<span style="color: #666666; font-style: italic;">// if tag is a closing tag</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^&lt;\s*\/([^\s]+?)\s*&gt;$/s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line_matchings</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: #000088;">$tag_matchings</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// delete tag from $open_tags list</span>
					<span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_search</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag_matchings</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: #000088;">$open_tags</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;">$pos</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: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$open_tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #666666; font-style: italic;">// if tag is an opening tag</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^&lt;\s*([^\s&gt;!]+).*?&gt;$/s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line_matchings</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: #000088;">$tag_matchings</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// add tag to the beginning of $open_tags list</span>
					<span style="color: #990000;">array_unshift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$open_tags</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag_matchings</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #666666; font-style: italic;">// add html-tag to $truncate'd text</span>
				<span style="color: #000088;">$truncate</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$line_matchings</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: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// calculate the length of the plain text part of the line; handle entities as one character</span>
			<span style="color: #000088;">$content_length</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&amp;[0-9a-z]{2,8};|&amp;#[0-9]{1,7};|[0-9a-f]{1,6};/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line_matchings</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">$total_length</span><span style="color: #339933;">+</span><span style="color: #000088;">$content_length</span><span style="color: #339933;">&gt;</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// the number of characters which are left</span>
				<span style="color: #000088;">$left</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$length</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$total_length</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$entities_length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// search for html entities</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&amp;[0-9a-z]{2,8};|&amp;#[0-9]{1,7};|[0-9a-f]{1,6};/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line_matchings</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$entities</span><span style="color: #339933;">,</span> PREG_OFFSET_CAPTURE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// calculate the real length of all entities in the legal range</span>
					<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$entities</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entity</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;">$entity</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;">1</span><span style="color: #339933;">-</span><span style="color: #000088;">$entities_length</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$left</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$left</span><span style="color: #339933;">--;</span>
							<span style="color: #000088;">$entities_length</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entity</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</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: #666666; font-style: italic;">// no more characters left</span>
							<span style="color: #b1b100;">break</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;">$truncate</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line_matchings</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$left</span><span style="color: #339933;">+</span><span style="color: #000088;">$entities_length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// maximum lenght is reached, so get off the loop</span>
				<span style="color: #b1b100;">break</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;">$truncate</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$line_matchings</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$total_length</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$content_length</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// if the maximum length is reached, get off the loop</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$total_length</span><span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">break</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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</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;">$truncate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span> <span style="color: #339933;">-</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ending</span><span style="color: #009900;">&#41;</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: #666666; font-style: italic;">// if the words shouldn't be cut in the middle...</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$exact</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// ...search the last occurance of a space...</span>
		<span style="color: #000088;">$spacepos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$truncate</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spacepos</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// ...and cut the text in this position</span>
			<span style="color: #000088;">$truncate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$truncate</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$spacepos</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: #666666; font-style: italic;">// add the defined ending to the text</span>
	<span style="color: #000088;">$truncate</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$ending</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$considerHtml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// close all unclosed html-tags</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$open_tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$truncate</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$tag</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$truncate</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ice cubes forming ice spikes as water freezes</title>
		<link>http://alanwhipple.com/2011/05/11/ice-cubes-forming-ice-spikes-water-freezes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ice-cubes-forming-ice-spikes-water-freezes</link>
		<comments>http://alanwhipple.com/2011/05/11/ice-cubes-forming-ice-spikes-water-freezes/#comments</comments>
		<pubDate>Wed, 11 May 2011 16:24:41 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=25</guid>
		<description><![CDATA[I&#8217;ve seen these many times over the years. Each time I was slightly curious, but never felt motivated to look it up &#8211; until today. These formations are commonly referred to as &#8220;ice spikes&#8221;. They seem to grow most readily with distilled water and an air current. They can also form with regular tap water, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://alanwhipple.com/wp-content/uploads/2011/06/ice-spike-icecube-650x487.jpg" alt="ice-spike-icecube" title="ice-spike-icecube" width="650" height="487" class="aligncenter size-large wp-image-26" /></p>
<p>I&#8217;ve seen these many times over the years. Each time I was slightly curious, but never felt motivated to look it up &#8211; until today.</p>
<p>These formations are commonly referred to as &#8220;ice spikes&#8221;. They seem to grow most readily with distilled water and an air current. They can also form with regular tap water, although much less frequently. Every time I have personally witnessed these formations has been using regular tap water in regular ice cube trays.</p>
<p>The idea is that the edges, including the surface, freeze faster than the interior of the ice cube. Water expands as it freezes, so if the surface is (nearly) frozen over, pressure will build up from the interior of the cube, and water will force its way up. This can form a tunnel or tube that the water travels up until freezing along the rim of the tube (forming the ice spike).</p>
<div id="attachment_10" class="wp-caption aligncenter" style="width: 566px"><img src="http://alanwhipple.com/wp-content/uploads/2011/06/ice-spike-formation.jpg" alt="ice-spike-formation" title="ice-spike-formation" width="556" height="446" class="size-full wp-image-10" /><p class="wp-caption-text">Illustration I stole from CalTech</p></div>
<p>CalTech with some good info:<br />
<a href="http://www.its.caltech.edu/~atomic/snowcrystals/icespikes/icespikes.htm">http://www.its.caltech.edu/~atomic/snowcrystals/icespikes/icespikes.htm</a></p>
<p>More links pertaining to ice spikes:<br />
<a href="http://www.physics.utoronto.ca/~smorris/edl/icespikes/icespikes.html">http://www.physics.utoronto.ca/~smorris/edl/icespikes/icespikes.html</a><br />
<a href="http://en.wikipedia.org/wiki/Ice_spike">http://en.wikipedia.org/wiki/Ice_spike</a><br />
<a href="http://www.halbertcicles.com/how.htm">http://www.halbertcicles.com/how.htm</a><br />
<a href="http://www.sciforums.com/Unexplainable-Water-Phenomenon-t-46063.html">http://www.sciforums.com/Unexplainable-Water-Phenomenon-t-46063.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2011/05/11/ice-cubes-forming-ice-spikes-water-freezes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux: Read / dump contents of DMB file created with httxt2dbm</title>
		<link>http://alanwhipple.com/2011/04/05/linux-read-dump-contents-dmb-file-created-httxt2dbm/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linux-read-dump-contents-dmb-file-created-httxt2dbm</link>
		<comments>http://alanwhipple.com/2011/04/05/linux-read-dump-contents-dmb-file-created-httxt2dbm/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 16:32:35 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=28</guid>
		<description><![CDATA[Berkley DB (DBM) files seem easy to create, but hard to read/manage. The most common task I can think of wanting to do on a database file is to dump or display it&#8217;s contents. And there&#8217;s no easy or straight forward way to do this (at least not that I found). We were creating DBM [...]]]></description>
			<content:encoded><![CDATA[<p>Berkley DB (DBM) files seem easy to create, but hard to read/manage. The most common task I can think of wanting to do on a database file is to dump or display it&#8217;s contents. And there&#8217;s no easy or straight forward way to do this (at least not that I found).</p>
<p>We were creating DBM files (from text files) for use by Apache/mod_rewrite using the <a href="http://httpd.apache.org/docs/2.2/programs/httxt2dbm.html">httxt2dbm</a> utility. If you create &#8220;file.dbm&#8221; it actually creates &#8220;file.dbm.pag&#8221; and &#8220;file.dbm.dir&#8221;.</p>
<p>To output the contents of the DBM file(s), Perl comes to the rescue. A colleague of mine wrote this after we searched the net for a working script and failed to find one. I&#8217;m sharing it in hopes someone will find it useful.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #666666; font-style: italic;">#- dumpdbm.pl</span>
<span style="color: #666666; font-style: italic;"># /path/to/dumpdbm.pl /path/to/file.dbm</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">use</span> SDBM_File<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #000000; font-weight: bold;">ARGV</span><span style="color: #339933;">;</span>
<span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Missing DBM name.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$name</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #339933;">%</span><span style="color: #000066;">map</span><span style="color: #339933;">;</span>
<span style="color: #000066;">tie</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">%</span><span style="color: #000066;">map</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'SDBM_File'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$name</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'O_RDONLY'</span><span style="color: #339933;">,</span> 0644 <span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't open DBM file<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$k</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #339933;">%</span><span style="color: #000066;">map</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;"># value is terminated by a null character, but the hash value contains cruft after that</span>
  <span style="color: #666666; font-style: italic;"># so cut off the value at the first \0</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@v</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\0</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$map</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$k</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">print</span> <span style="color: #0000ff;">$k</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$v</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: #ff0000;">&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: #000066;">untie</span> <span style="color: #339933;">%</span><span style="color: #000066;">map</span><span style="color: #339933;">;</span>
<span style="color: #000066;">exit</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2011/04/05/linux-read-dump-contents-dmb-file-created-httxt2dbm/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FTP files from Unix to Windows and get double lines</title>
		<link>http://alanwhipple.com/2011/03/12/ftp-files-unix-windows-double-lines/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ftp-files-unix-windows-double-lines</link>
		<comments>http://alanwhipple.com/2011/03/12/ftp-files-unix-windows-double-lines/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 17:34:28 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=30</guid>
		<description><![CDATA[Sometimes, but not always, you&#8217;ll download a file from a Unix server to your Windows workstation, only to find that all line breaks have been doubled! This consistently happens to me when downloading WordPress theme files that have been edited using the WordPress theme editor (thus modified by the server). The FTP client can have [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, but not always, you&#8217;ll download a file from a Unix server to your Windows workstation, only to find that all line breaks have been doubled! This consistently happens to me when downloading WordPress theme files that have been edited using the WordPress theme editor (thus modified by the server).</p>
<p>The FTP client can have its default transfer type set to ASCII, Binary, or Auto. The problem seems to be resolved by setting it to Binary. If that doesn&#8217;t work, try ASCII.</p>
<p>But maybe the damage has already been done. Maybe it&#8217;s been downloaded and uploaded multiple times, so now the extra lines are part of the real file. Many <a href="http://en.wikipedia.org/wiki/Integrated_development_environment">IDEs</a> have a tool to apply source formatting. For example in Dreamweaver, Commands->Apply Source formatting.</p>
<p>There are many ways/tools to remove blank lines. A quick and easy online tool may be just what you need:<br />
<a href="http://textmechanic.com/Remove-Empty-Lines.html">http://textmechanic.com/Remove-Empty-Lines.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2011/03/12/ftp-files-unix-windows-double-lines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big sites NOT using &#8216;www&#8217; in their domain</title>
		<link>http://alanwhipple.com/2010/02/10/big-sites-www-domain/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=big-sites-www-domain</link>
		<comments>http://alanwhipple.com/2010/02/10/big-sites-www-domain/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 17:36:02 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[DNS]]></category>
		<category><![CDATA[Web General]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=32</guid>
		<description><![CDATA[This is a list of major websites I&#8217;ve encountered that don&#8217;t use &#8216;www&#8217; in their primary URL. The criteria of the list is: the site must use the root domain, actively redirect all &#8216;www&#8217; requests to the root domain, and have a Google page rank greater than 6. http://twitter.com/ http://slashdot.org/ http://digg.com/ http://thesaurus.com/ http://nymag.com/ http://mashable.com/ http://allthingsd.com/ [...]]]></description>
			<content:encoded><![CDATA[<p>This is a list of major websites I&#8217;ve encountered that don&#8217;t use &#8216;www&#8217; in their primary URL. The criteria of the list is: the site must use the root domain, actively redirect all &#8216;www&#8217; requests to the root domain, and have a Google page rank greater than 6.</p>
<p><a href=" http://twitter.com/">http://twitter.com/</a><br />
<a href="http://slashdot.org/">http://slashdot.org/</a><br />
<a href="http://digg.com/">http://digg.com/</a><br />
<a href="http://thesaurus.com/">http://thesaurus.com/</a><br />
<a href="http://nymag.com/">http://nymag.com/</a><br />
<a href="http://mashable.com/">http://mashable.com/</a><br />
<a href="http://allthingsd.com/">http://allthingsd.com/</a><br />
<a href="http://bigthink.com/">http://bigthink.com/</a><br />
<a href="http://wordpress.org/">http://wordpress.org/</a><br />
<a href="http://wordpress.com/">http://wordpress.com/</a><br />
<a href="http://bbpress.org/">http://bbpress.org/</a><br />
<a href="http://drupal.org/">http://drupal.org/</a><br />
<a href="http://jquery.com/">http://jquery.com/</a><br />
<a href="http://portableapps.com/">http://portableapps.com/</a><br />
<a href="http://daringfireball.net/">http://daringfireball.net/</a><br />
<a href="http://stackoverflow.com/">http://stackoverflow.com/</a><br />
<a href="http://meyerweb.com/">http://meyerweb.com/</a><br />
<a href="http://github.com/">http://github.com/</a><br />
<a href="http://js-kit.com/">http://js-kit.com/</a><br />
<a href="http://clearleft.com/">http://clearleft.com/</a><br />
<a href="http://tinyurl.com/">http://tinyurl.com/</a><br />
<a href="http://bit.ly/">http://bit.ly/</a><br />
<a href="http://tr.im/">http://tr.im/</a></p>
<p>And all the Gawker Media sites (running on the same platform):<br />
<a href="http://gawker.com/">http://gawker.com/</a><br />
<a href="http://deadspin.com/">http://deadspin.com/</a><br />
<a href="http://kotaku.com/ ">http://kotaku.com/ </a><br />
<a href="http://jezebel.com/">http://jezebel.com/</a><br />
<a href="http://io9.com/ ">http://io9.com/</a><br />
<a href="http://jalopnik.com/ ">http://jalopnik.com/</a><br />
<a href="http://gizmodo.com/">http://gizmodo.com/</a><br />
<a href="http://lifehacker.com/">http://lifehacker.com/</a></p>
<h3>CNAME</h3>
<p>The only GOOD reason I&#8217;ve seen for being hesitant about not using &#8216;www&#8217; is that you CANNOT create a CNAME record for the root domain. CNAME records are only valid when there is no other DNS for that domain, and the root domain always has other records.</p>
<blockquote><p>As the root of a domain must have an SOA and NS records the rule above kicks in, preventing use of CNAMEs too.<br />
<a href="http://serverfault.com/questions/170194/why-cant-a-domains-root-be-a-cname">http://serverfault.com/questions/170194/why-cant-a-domains-root-be-a-cname</a></p></blockquote>
<p>Some Content Distribution Networks (CDN), like <a href="http://en.wikipedia.org/wiki/Akamai_Technologies">Akamai</a> and <a href="http://en.wikipedia.org/wiki/Cotendo">Cotendo</a>, use CNAME records as the method for one to hand over their website to the caching network. If you wanted to strictly use the root domain (no www), Akamai will tell you that you can&#8217;t due to the inability to create a CNAME record. CNAMEs are generally useful things. </p>
<p>There are a few ways around this:</p>
<ol>
<li>Work out a special deal with the CDN to not rely on CNAME records (If Digg is really a Cotendo customer, it&#8217;s proof it can be done)</li>
<li>Use a different CDN that doesn&#8217;t require CNAME records (Anyone know any? <a href="http://en.wikipedia.org/wiki/Level_3_Communications">Level 3</a> perhaps?)</li>
<li>Use something else. Perhaps a high power/bandwidth super intelligent load balancer.</li>
</ol>
<p>If anyone stumbles upon this article and has details on how any of these sites are able to scale while using their root domain, please share! My work-arounds list needs some work.</p>
]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2010/02/10/big-sites-www-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Plugin: Import Blogroll With Categories</title>
		<link>http://alanwhipple.com/2009/04/28/wordpress-plugin-import-blogroll-categories/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-plugin-import-blogroll-categories</link>
		<comments>http://alanwhipple.com/2009/04/28/wordpress-plugin-import-blogroll-categories/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 16:38:56 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=34</guid>
		<description><![CDATA[I just wrote my first official WordPress plugin and have it listed in the WordPress plugin repository! Import Blogroll With Categories By default, WordPress is lacking the functionality to handle categorized OPML feeds of links. When importing blogroll/links you are FORCED to select ONE category for ALL links to be inserted into. My plugin adds [...]]]></description>
			<content:encoded><![CDATA[<p>I just wrote my first official WordPress plugin and have it listed in the WordPress plugin repository! <a href="http://wordpress.org/extend/plugins/import-blogroll-with-categories/">Import Blogroll With Categories</a></p>
<p>By default, WordPress is lacking the functionality to handle categorized OPML feeds of links. When importing blogroll/links you are FORCED to select ONE category for ALL links to be inserted into.</p>
<p>My plugin adds an importer to WordPress, which is actually a modification of the standard OPML importer shipped with WP 2.7. The improved importer actually handles categories.</p>
<p>If the link categories already exist in your blog, links from the import within matching (case-insensitive) category names will be inserted into the correct category.</p>
<p>You can specify one of two options for the case where your blog doesn&#8217;t already have some categories that are found in the feed.</p>
<p>1) Allow it to create any new link categories needed (and insert the links into them)<br />
2) Specify a default category that the links from unknown categories will be inserted into</p>
<p>I got jump start on some the coding changes a while ago here: <a href="http://www.dyers.org/blog/archives/2008/02/27/how-to-hack-the-wordpress-blogroll-importer-to-recognize-categories-from-your-feed-reader/">http://www.dyers.org/blog/archives/2008/02/27/how-to-hack-the-wordpress-blogroll-importer-to-recognize-categories-from-your-feed-reader/</a></p>
<p>Until YESTERDAY there has been <a href="http://core.trac.wordpress.org/ticket/6393">an item in the WordPress Trac</a> that indicated that the milestone for its implementation in WordPress was version 2.8. I believe it would have nullified the reason for my plugin to exist. However, apparently, someone just changed the milestone from 2.8 to &#8220;Future Release (no date set)&#8221;.</p>
<p>So it looks like my plugin will still be useful for a long time =)</p>
<p>I&#8217;ve documented the steps of creating a plugin and getting it into the WordPress plugin repository here: <a href="http://alanwhipple.com/2009/04/28/writing-wordpress-plugin/">Writing a WordPress Plugin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2009/04/28/wordpress-plugin-import-blogroll-categories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a WordPress Plugin</title>
		<link>http://alanwhipple.com/2009/04/28/writing-wordpress-plugin/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=writing-wordpress-plugin</link>
		<comments>http://alanwhipple.com/2009/04/28/writing-wordpress-plugin/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 16:20:35 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=36</guid>
		<description><![CDATA[I just wrote my first official WordPress plugin and have it listed in the WordPress plugin repository! Import Blogroll With Categories I discuss the plugin in a separate post: WordPress Plugin: Import Blogroll With Categories Since this was my first official WordPress plugin, I wanted to document the procedure. Writing a plugin and going all [...]]]></description>
			<content:encoded><![CDATA[<p>I just wrote my first official WordPress plugin and have it listed in the WordPress plugin repository! <a href="http://wordpress.org/extend/plugins/import-blogroll-with-categories/">Import Blogroll With Categories</a> </p>
<p>I discuss the plugin in a separate post: <a href="http://alanwhipple.com/2009/04/28/wordpress-plugin-import-blogroll-categories/">WordPress Plugin: Import Blogroll With Categories</a>  </p>
<p>Since this was my first official WordPress plugin, I wanted to document the procedure. Writing a plugin and going all the way with it, is not for the faint-of-heart.</p>
<p>First, you actually have to come up with an idea that:<br />
1) No one has written a plugin for yet (search for it!)<br />
2) Is doable without donating years of your life<br />
3) Functionality you really want!</p>
<p>Then you actually have to create the plugin. You’ll probably have to use multiple hooks called actions and filters. I wish I could tell you there was some easy way to learn exactly which you use and how to use them, but it seems to be something you mostly have to figure out on your own. Studying the code of other plugins you like will probably help.</p>
<p>In PHP you can&#8217;t override user defined functions, but you CAN override all the WordPress functions defined in: <strong><em>wp-includes/pluggable.php</em></strong>. WordPress only defines the default functions if plugin defined versions don&#8217;t exist.</p>
<p>Various sites provide a comprehensive list of WordPress functions, classes, and variables and indicates within which files they are used and defined. <a href="http://phpdoc.wordpress.org/">WordPress provides a decent one</a>.</p>
<p>Many editors (including Dreamweaver) include a method to search over all files within a directory. The feature goes by many names and is not always easy to find, but is a life-saver for tracking down functions/code.</p>
<p>The general WordPress plugin creation guide: <a href="http://codex.wordpress.org/Writing_a_Plugin">http://codex.wordpress.org/Writing_a_Plugin</a></p>
<p>After your plugin has been created, relatively well tested, and refined, a whole different journey begins (if you want your plugin in the WordPress plugin repository). </p>
<p>I chose to put my plugin on wordpress.org because I think it is best place for WP plugins to reside. It makes the most sense to users. WP is integrated with the automatic plugin installer/updater. It serves are one solid place to look for plugins that are all documented in the same fashion. If you are serious about your plugin, I recommend you follow the required steps to get it up there.</p>
<p>You need to submit a request to add your plugin. The request has to approved by a person. I had to wait 2 days to get my request approved. When you make the request, make sure you use the plugin name you want to use, and a solid description.</p>
<p>When approved, you will get access to a SVN (Subversion) directory just for your plugin. Like this: <strong><em>http://svn.wp-plugins.org/name-of-your-plugin/ </em></strong></p>
<p>What they don&#8217;t clearly explain, is how to actually upload your files. The only page they refer you to is: <a href="http://wordpress.org/extend/plugins/about/svn/">http://wordpress.org/extend/plugins/about/svn/</a></p>
<p>Which is SOMEWHAT useful, but it is all in command-line. They make no reference to Subversion clients. When it comes to file transfer, I would prefer a nice GUI. For comparison, FTP is also a command-line based tool but we all use FTP clients don&#8217;t we?</p>
<p>After studying <a href="http://en.wikipedia.org/wiki/Comparison_of_Subversion_clients">this chart of Subversion clients</a>, I decided to try out<a href="http://www.syntevo.com/smartsvn/features.html"> SmartSVN</a> (free)</p>
<p>I&#8217;ll admit it’s a bit overkill for updating a single plugin, but maybe I&#8217;ll use it for other SVN connections in the future. Once I got the authentication figured out (wordpress.org login), I had no problems using the program. It worked pretty much just like I expected. Easy to see if a file has been changed locally or remotely, and update the files.</p>
<p>SmartSVN has a ton of features, and I only used the basic stuff, so if I start using it more, perhaps I&#8217;ll write a post reviewing its features.</p>
<p>After uploading files (use the general guidelines <a href="http://wordpress.org/extend/plugins/about/svn/">here</a> and <a href="http://wordpress.org/extend/plugins/about/faq/">here</a>), you can expect to wait up to 15 minutes to see your changes reflected on <a href="http://wordpress.org/extend/plugins/">http://wordpress.org/extend/plugins/</a></p>
<p>BEFORE you upload anything you&#8217;ll want to do the most important thing. To create a VERY specifically formatted readme.txt file. This readme.txt file is used to CREATE your plugins page at: http://wordpress.org/extend/plugins/your-plugin-name/</p>
<p>You don&#8217;t have special admin access to update that page. The page is entirely controlled by the contents of your SVN directory (especially the readme.txt).</p>
<p>Because the readme.txt file is so important, WordPress provided a couple nice resources. An <a href="http://wordpress.org/extend/plugins/about/readme.txt">example readme.txt file</a> containing notes about how to format your text. And a <a href="http://wordpress.org/extend/plugins/about/validator/">readme.txt validator</a>. The validator is sweet. Not only does it validate your file, but it gives you a PREVIEW of the generated HTML formatting. This preview will help you work out formatting issues before you upload anything to your SVN folder.</p>
<p>Remember, your plugin will be live (in about 15 minutes) after you first upload your plugin file and valid readme.txt file. So try to already have a complete and properly formatted readme.txt file before you upload anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2009/04/28/writing-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Non-regex trim function</title>
		<link>http://alanwhipple.com/2009/02/20/javascript-non-regex-trim-function/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript-non-regex-trim-function</link>
		<comments>http://alanwhipple.com/2009/02/20/javascript-non-regex-trim-function/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 17:43:14 +0000</pubDate>
		<dc:creator>Alan Whipple</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://alanwhipple.com/?p=39</guid>
		<description><![CDATA[Surprisingly, JavaScript does not have a native &#8220;trim&#8221; function. Trim should remove all whitespace from the beginning and ending of a string. If you are using jQuery, you can use jQuery trim. Many other libraries include a trim function. If you Google for JavaScript trim functions, you&#8217;ll find that they usually use regular expressions. One [...]]]></description>
			<content:encoded><![CDATA[<p>Surprisingly, JavaScript does not have a native &#8220;trim&#8221; function. Trim should remove all whitespace from the beginning and ending of a string. If you are using jQuery, you can use <a href="http://api.jquery.com/jQuery.trim/">jQuery trim</a>. Many other libraries include a trim function.</p>
<p>If you Google for JavaScript trim functions, you&#8217;ll find that they usually use regular expressions. One would think that would be good enough. However, I encountered a situation where the typical regex whitespace trim functions simply weren&#8217;t working. Perhaps it is was an unusual whitespace character?</p>
<p>I found <a href="http://blog.stevenlevithan.com/archives/faster-trim-javascript">a great article</a> that compared different JavaScript trim functions. The function he listed as &#8220;trim10&#8243; does not use regular expressions at all. It is also one of the best performers in terms of efficiency/speed. Most importantly, this function successfully trimmed my pesky whitespace! </p>
<p>Sharing this fast, functional, non-regex JavaScript trim function in hopes it&#8217;ll be useful:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> trim <span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> whitespace <span style="color: #339933;">=</span> <span style="color: #3366CC;">' <span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\f</span><span style="color: #000099; font-weight: bold;">\x</span>0b<span style="color: #000099; font-weight: bold;">\x</span>a0<span style="color: #000099; font-weight: bold;">\u</span>2000<span style="color: #000099; font-weight: bold;">\u</span>2001<span style="color: #000099; font-weight: bold;">\u</span>2002<span style="color: #000099; font-weight: bold;">\u</span>2003<span style="color: #000099; font-weight: bold;">\u</span>2004<span style="color: #000099; font-weight: bold;">\u</span>2005<span style="color: #000099; font-weight: bold;">\u</span>2006<span style="color: #000099; font-weight: bold;">\u</span>2007<span style="color: #000099; font-weight: bold;">\u</span>2008<span style="color: #000099; font-weight: bold;">\u</span>2009<span style="color: #000099; font-weight: bold;">\u</span>200a<span style="color: #000099; font-weight: bold;">\u</span>200b<span style="color: #000099; font-weight: bold;">\u</span>2028<span style="color: #000099; font-weight: bold;">\u</span>2029<span style="color: #000099; font-weight: bold;">\u</span>3000'</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> str.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>whitespace.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			str <span style="color: #339933;">=</span> str.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> str.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>whitespace.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			str <span style="color: #339933;">=</span> str.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> i <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> whitespace.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">?</span> str <span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://alanwhipple.com/2009/02/20/javascript-non-regex-trim-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

