<?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>Tierra BLOG &#187; Doug</title>
	<atom:link href="http://www.tierra-innovation.com/blog/author/doug/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tierra-innovation.com/blog</link>
	<description>Innovation in technology, strategy and design</description>
	<lastBuildDate>Fri, 30 Apr 2010 16:09:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to change the src attribute in a HTML5 video tag</title>
		<link>http://www.tierra-innovation.com/blog/2010/04/02/how-to-change-the-src-attribute-in-a-html5-video-tag/</link>
		<comments>http://www.tierra-innovation.com/blog/2010/04/02/how-to-change-the-src-attribute-in-a-html5-video-tag/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 13:39:51 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=712</guid>
		<description><![CDATA[So imagine you have a HTML5 video tag on your page running on autoplay and you want to switch the video out with another one.   So you figure, &#8220;I&#8217;ll just change the &#8217;src&#8217; attribute via javascript and like an image tag it will start playing the new video&#8221;.  Nope.  After fruitlessly searching for a [...]]]></description>
			<content:encoded><![CDATA[<p>So imagine you have a HTML5 video tag on your page running on autoplay and you want to switch the video out with another one.   So you figure, &#8220;I&#8217;ll just change the &#8217;src&#8217; attribute via javascript and like an image tag it will start playing the new video&#8221;.  Nope.  After fruitlessly searching for a solution via Google or directly on StackOverflow I decided to dig in and read the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html">HTML5 video docs</a>.  Here is what I came up with:</p>
<pre>function switchVideo(videoTagId, newUrl) {
  var videoTag = document.getElementById(videoTagId);
  if (videoTag) {
    videoTag.pause();
    videoTag.src = newUrl;
    videoTag.load();
    // the .play() call might not be needed if your video tag
    // is set for autoplay but it can't hurt to call it
    videoTag.play();
  }
}</pre>
<p>Add a comment if you have a different way to do the same thing.  I&#8217;m curious.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2010/04/02/how-to-change-the-src-attribute-in-a-html5-video-tag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Tip: Inline StdClass Object Creation</title>
		<link>http://www.tierra-innovation.com/blog/2009/06/26/php-tip-inline-stdclass-object-creation/</link>
		<comments>http://www.tierra-innovation.com/blog/2009/06/26/php-tip-inline-stdclass-object-creation/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 14:07:22 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=618</guid>
		<description><![CDATA[One of my pet peeves is that PHP does not have syntax to support inline StdClass object creation. This tip shows you how.]]></description>
			<content:encoded><![CDATA[<p>One of my pet peeves is that PHP does not have syntax to support inline StdClass object creation.  Something like this would be great:</p>
<p>$foo = {&#8220;bar&#8221;: &#8220;baz&#8221;, &#8220;bam&#8221;: &#8220;boom&#8221;};</p>
<p>so you end up doing something like this:</p>
<p>$foo = new StdClass;<br />
$foo-&gt;bar = &#8220;baz&#8221;;<br />
$foo-&gt;bam = &#8220;boom&#8221;;</p>
<p>but you don&#8217;t have to.  Using PHP&#8217;s casting operator you can create the object in one line:</p>
<p>$foo = (object) array(&#8220;bar&#8221; =&gt; &#8220;baz&#8221;, &#8220;bam&#8221; =&gt; &#8220;boom&#8221;);</p>
<p>Which I think looks a lot cleaner.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2009/06/26/php-tip-inline-stdclass-object-creation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>MySQL Snippet: Pick a Daily Featured Item Automatically</title>
		<link>http://www.tierra-innovation.com/blog/2009/06/24/mysql-snippet-pick-a-daily-featured-item-automatically/</link>
		<comments>http://www.tierra-innovation.com/blog/2009/06/24/mysql-snippet-pick-a-daily-featured-item-automatically/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 15:41:46 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=603</guid>
		<description><![CDATA[Here is how to add a featured item on your website that changes automatically each day.  For this example let's assume you have an e-commerce site with a MySQL table called "products" that has a column called stock_count which contains the count of each product in stock.  We want to feature products in stock, changing daily and also changing automatically if during the day the product goes out of stock.]]></description>
			<content:encoded><![CDATA[<p>Here is how to add a featured item on your website that changes automatically each day.  For this example let&#8217;s assume you have an e-commerce site with a MySQL table called &#8220;products&#8221; that has a column called stock_count which contains the count of each product in stock.  We want to feature products in stock, changing daily and also changing automatically if during the day the product goes out of stock.</p>
<p>First we need to pick a stock to feature, this query does that:</p>
<pre>select date_format(now(),'%j') % count(*) from products
where stock_count &gt; 0</pre>
<p>The date_format() function returns the ordinal day of the year for the current day, a number in the range of 1 to 366.  We take that number and do a modulus by the number of total in stock products to get an index (not an id) of today&#8217;s in stock product.</p>
<p>Next we need to get the product picked from the first query.  Lets assume you stored the result of the previous query into a variable named $index.  Here is the query:</p>
<pre>select * from products where stock_count &gt; 0 order by id
limit $index, 1</pre>
<p>You now have the product information to display on your page.</p>
<p>NOTE: If you are using PHP, you can optimize the first query so that MySQL will cache it by removing the now() call.   To do this first use the PHP date() function to get the current day of the year and then use it like this:</p>
<pre>$i = date("z") + 1; // date returns 0..365
$sql = "select $i % count(*) from products where stock_count &gt; 0";</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2009/06/24/mysql-snippet-pick-a-daily-featured-item-automatically/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Preprocessing Moveable Type import files for Wordpress</title>
		<link>http://www.tierra-innovation.com/blog/2009/06/17/code-snippet-preprocessing-moveable-type-import-files-for-wordpress/</link>
		<comments>http://www.tierra-innovation.com/blog/2009/06/17/code-snippet-preprocessing-moveable-type-import-files-for-wordpress/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 16:05:35 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=596</guid>
		<description><![CDATA[We've moved a couple of clients from older Moveable Type installations to Wordpress and each time Wordpress doesn't handle the text paragraph formating from the Moveable Type import file.  Here is a quick script we created to convert the BODY and EXTENDED BODY sections of the Moveable Type import file to HTML paragraph formatting.]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve moved a couple of clients from older Moveable Type installations to Wordpress and each time Wordpress doesn&#8217;t handle the text paragraph formating from the Moveable Type import file.  Here is a quick script we created to convert the BODY and EXTENDED BODY sections of the Moveable Type import file to HTML paragraph formatting.</p>
<pre>&lt;?php</pre>
<pre>// TODO: change this to your Moveable Type import filename
$filename = "import.txt";

$inBodyOrExtendedBody = false;
$output = array();</pre>
<pre>foreach (explode("\n", file_get_contents($filename)) as $line) {
  if ($inBodyOrExtendedBody) {
    $inBodyOrExtendedBody = ($line != "-----");
    if (!$inBodyOrExtendedBody)
      $output[] = "&lt;/p&gt;";
  }</pre>
<pre>  if ($inBodyOrExtendedBody) {
    if (trim($line) == "") {
      $output[] = "&lt;/p&gt;";
      $output[] = "&lt;p&gt;";
    }
    else
      $output[] = $line . "&lt;br/&gt;";
  }
  else {
    $output[] = $line;
    $inBodyOrExtendedBody = ($line == "BODY:") ||
                            ($line == "EXTENDED BODY:");
    if ($inBodyOrExtendedBody)
      $output[] = "&lt;p&gt;";
    }
  }</pre>
<pre>  // remove the trailing &lt;br/&gt; before &lt;/p&gt;
  // and the empty paragraphs before outputing
  echo str_replace("&lt;br/&gt;\n&lt;/p&gt;", "\n&lt;/p&gt;",
                   str_replace("&lt;p&gt;\n&lt;/p&gt;", "",
                   implode("\n", $output)));
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2009/06/17/code-snippet-preprocessing-moveable-type-import-files-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing: Merging code and design</title>
		<link>http://www.tierra-innovation.com/blog/2009/05/11/processing-merging-code-and-design/</link>
		<comments>http://www.tierra-innovation.com/blog/2009/05/11/processing-merging-code-and-design/#comments</comments>
		<pubDate>Mon, 11 May 2009 14:05:59 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=553</guid>
		<description><![CDATA[<a href="http://processing.org/download/index.html" target="blank" title="Screen grab from the Processing application" ><img class="imgLeft" title="Screen grab from the Processing application" src="http://www.tierra-innovation.com/blog/wp-content/uploads/2009/05/processing1.jpg" alt="Screen grab from the Processing application/" /></a>

Last week the local software developers group that I am a member of hosted a talk by <a href="http://benfry.com/">Ben Fry</a>, the co-creator of <a href="http://processing.org/">Processing</a>.  Ben holds a doctorate from the MIT Media Lab where he was a part of the <a href="http://acg.media.mit.edu/">Aesthetics + Computation Group</a>.  ACG's purpose is to "...work toward the design of advanced system architectures and thought processes to enable the creation of (as yet) unimaginable forms and spaces".  In other words, very cool stuff.]]></description>
			<content:encoded><![CDATA[<p><a href="http://processing.org/download/index.html" target="blank" title="Screen grab from the Processing application" ><img class="imgLeft" title="Screen grab from the Processing application" src="http://www.tierra-innovation.com/blog/wp-content/uploads/2009/05/processing1.jpg" alt="Screen grab from the Processing application/" /></a></p>
<p>Last week the local software developers group that I am a member of hosted a talk by <a href="http://benfry.com/">Ben Fry</a>, the co-creator of <a href="http://processing.org/">Processing</a>.  Ben holds a doctorate from the MIT Media Lab where he was a part of the <a href="http://acg.media.mit.edu/">Aesthetics + Computation Group</a>.  ACG&#8217;s purpose is to &#8220;&#8230;work toward the design of advanced system architectures and thought processes to enable the creation of (as yet) unimaginable forms and spaces&#8221;.  In other words, very cool stuff.</p>
<p>Ben is a unique mix of designer and developer.  Along with developing Processing his own personal design work (taken from his <a href="http://benfry.com/about/">about</a> page) has been shown at &#8220;the Whitney Biennial in 2002 and the Cooper Hewitt Design Triennial in 2003. Other pieces have appeared in the Museum of Modern Art in New York, at Ars Electronica in Linz, Austria and in the films Minority Report and The Hulk. His information graphics have also illustrated articles for the journal Nature, New York Magazine, The New York Times, Seed, and Communications of the ACM.&#8221;</p>
<p>The talk itself lasted about an hour and a half and was a high level review of how Processing tries to integrate the worlds of programming and design.  Ben walked us through the work he did as a postdoc creating interesting and interactive visualizations of complex genetic data.  The most impressive visualization was a series of charts showing the relationships of single letter changes in the human genome, <a href="http://benfry.com/isometricblocks/">available here</a> (warning: this loads a Java applet).</p>
<p>By definition pictures speak louder that words when talking about visulatization.  I encourage you to check out the &#8220;<a href="http://processing.org/exhibition/">curated exhibition</a>&#8221; at processing.org.  There is some amazing stuff there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2009/05/11/processing-merging-code-and-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Continuous PHP Profiling</title>
		<link>http://www.tierra-innovation.com/blog/2009/04/28/continuous-php-profiling/</link>
		<comments>http://www.tierra-innovation.com/blog/2009/04/28/continuous-php-profiling/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 15:11:03 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=519</guid>
		<description><![CDATA[Donald Knuth, the demi-god of computer science, famously once said "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."  Though often quoted it is easy to misunderstand what Knuth was saying - its not that you should ignore performance until the project is complete, tacking on an "optimize code" task at the end, rather it's that your design should not be complicated by performance considerations from the start. ]]></description>
			<content:encoded><![CDATA[<p>Donald Knuth, the demi-god of computer science, famously once said &#8220;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.&#8221;  Though often quoted it is easy to misunderstand what Knuth was saying &#8211; its not that you should ignore performance until the project is complete, tacking on an &#8220;optimize code&#8221; task at the end, rather it&#8217;s that your design should not be complicated by performance considerations from the start.  </p>
<p>Continuous profiling is opposite of premature optimization.  If done right continuous profiling is like the gauges on a car dashboard.  The information is always there and every few moments you glance down to see how you are doing and if any big red lights have come on.  Instead of speed, oil temperature and engine RPM you have execution time, memory used and query times.</p>
<p>Here at Tierra we use a range of continuous profiling.  Our internal CMS framework offers a rich set of data tacked to the bottom of the page.  By default it is enabled in our individual and group development deployments and disabled on our preview and production servers.  The profiling info includes the files included, the individual queries run and their execution time and as a byproduct of the framework architecture the duration of pluggable calls in the CMS.  The profiling data was modeled on what <a href="http://docs.kohanaphp.com/libraries/profiler">Konaha&#8217;s profiler</a> displays. For our Wordpress work we also have <a href="http://wordpress.org/extend/plugins/wpdb-profiling/">query profiling plugin for Wordpress</a> that we use to gauge the &#8220;query weight&#8221; of each plugin.  </p>
<p>So what if you don&#8217;t want to role your own?  <a href="http://particletree.com/features/php-quick-profiler/">PQP</a>, the &#8220;PHP Quick Profiler&#8221;, a recently introduced library from the folks behind wufoo.com is all you&#8217;ll need.  Its multiple tab interface and BIG text at the top really does look like a car dashboard.  All they forgot was the &#8220;Check Application&#8221; light.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2009/04/28/continuous-php-profiling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pragmatic Thinking and Learning: Refactor Your Wetware</title>
		<link>http://www.tierra-innovation.com/blog/2009/01/09/pragmatic-thinking-and-learning-refactor-your-wetware/</link>
		<comments>http://www.tierra-innovation.com/blog/2009/01/09/pragmatic-thinking-and-learning-refactor-your-wetware/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 14:45:48 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=329</guid>
		<description><![CDATA[<a href="http://pragprog.com/titles/ahptl/pragmatic-thinking-and-learning"><img class="alignleft size-full wp-image-330" title="ahptl" src="http://www.tierra-innovation.com/blog/wp-content/uploads/2009/01/ahptl.jpg" alt="ahptl" width="190" height="228" style="border-color: #888"/></a> 

I just finished a great book last night, <a href="http://pragprog.com/titles/ahptl/pragmatic-thinking-and-learning">Pragmatic Thinking and Learning: Refactor Your Wetware</a>, and I thought I would write a little review while it is still fresh in my mind.]]></description>
			<content:encoded><![CDATA[<p><a href="http://pragprog.com/titles/ahptl/pragmatic-thinking-and-learning"><img class="alignleft size-full wp-image-330" title="ahptl" src="http://www.tierra-innovation.com/blog/wp-content/uploads/2009/01/ahptl.jpg" alt="ahptl" width="190" height="228" align=left style="margin-top: 2px; margin-bottom: 2px; margin-right: 15px; border-color: #888"/></a> I just finished a great book last night, <a href="http://pragprog.com/titles/ahptl/pragmatic-thinking-and-learning">Pragmatic Thinking and Learning: Refactor Your Wetware</a>, and I thought I would write a little review while it is still fresh in my mind.</p>
<p>The author, Andy Hunt, uses the book to present a broad survey of current cognitive science and psychology using the language of software developers.  Its a nice combination of background material and practical tools and examples.  While I had read about most of the material in the book already from other sources it does a great job of pulling all the information and tools together to help you understand it all in context (one of the author&#8217;s favorite words). </p>
<p>The book is filled with suggestions to try concepts out in the book and I plan to do just that.  I&#8217;m building a project wiki after I complete this post to better understand and track an ongoing requirements document for a project that I am working on.</p>
<p>I&#8217;d recommend the book to any developers out there.  I plan to read it again soon myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2009/01/09/pragmatic-thinking-and-learning-refactor-your-wetware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Years Habits</title>
		<link>http://www.tierra-innovation.com/blog/2009/01/05/new-years-habits/</link>
		<comments>http://www.tierra-innovation.com/blog/2009/01/05/new-years-habits/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 20:03:57 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=321</guid>
		<description><![CDATA[<a href="http://www.loufranco.com/habits/"><img src="http://www.tierra-innovation.com/blog/wp-content/uploads/2009/01/habits.jpg" alt="habits" title="habits" width="100" height="100" class="alignnone size-full wp-image-322" border="0"/></a>

Looking for a quick and easy way to track all those New Year resolutions?  Habits, an iPhone app from Lou Franco, lets you enter a set of recurring tasks and set how often you want to see them pop up in your to do list.  It's a great way to help those resolutions last past the second week on January.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.loufranco.com/habits/"><img src="http://www.tierra-innovation.com/blog/wp-content/uploads/2009/01/habits.jpg" alt="habits" title="habits" width="100" height="100" class="alignnone size-full wp-image-322" border="0"/></a></p>
<p>Looking for a quick and easy way to track all those New Year resolutions?  Habits, an iPhone app from Lou Franco, lets you enter a set of recurring tasks and set how often you want to see them pop up in your to do list.  It&#8217;s a great way to help those resolutions last past the second week on January.</p>
<p>* Disclaimer: Lou is a friend but I&#8217;m not getting a cut of the massive 99 cent price per copy.  Yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2009/01/05/new-years-habits/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Trimming text on word boundaries in PHP</title>
		<link>http://www.tierra-innovation.com/blog/2008/12/16/code-snippet-trimming-text-on-word-boundaries-in-php/</link>
		<comments>http://www.tierra-innovation.com/blog/2008/12/16/code-snippet-trimming-text-on-word-boundaries-in-php/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 16:12:56 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=302</guid>
		<description><![CDATA[I thought I’d share a code snippet that I wrote this morning to truncate long news titles that appear on the homepage of WNET’s worldfocus.org site. The code truncates on the nearest word boundary if the text is longer than the requested maximum length.]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d share a code snippet that I wrote this morning to truncate long news titles that appear on the homepage of WNET&#8217;s <a href="http://worldfocus.org/">worldfocus.org</a> site.  The code truncates on the nearest word boundary if the text is longer than the requested maximum length.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> truncate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$max_length</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;...&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><span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_length</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</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;">&gt;</span> <span style="color: #000088;">$max_length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$more_length</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$more</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$text_length</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_length</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$more_length</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$text_length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</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: #000088;">$text_length</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000088;">$text_length</span><span style="color: #339933;">--;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$text_length</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000088;">$text_length</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_length</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$more_length</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$text</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;">$text_length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
            <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$more</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;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Example usage:</p>
<pre>truncate("this is a very long sentence", 15)</pre>
<p><b>Update:</b></p>
<p>Based on a comment on the PHP subreddit pointing me to the Smarty truncation function along with <i>frans</i> comment below I&#8217;ve tightend up the function to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> truncate2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$max_length</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;...&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><span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_length</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</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;">&gt;</span> <span style="color: #000088;">$max_length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$max_length</span> <span style="color: #339933;">-=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_length</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$more</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;">// from Smarty code</span>
    <span style="color: #000088;">$space_pos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</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;">$max_length</span><span style="color: #009900;">&#41;</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: #000088;">$text</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;">$space_pos</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span> ? <span style="color: #000088;">$max_length</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$space_pos</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$more</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;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2008/12/16/code-snippet-trimming-text-on-word-boundaries-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Simple Desk Hack</title>
		<link>http://www.tierra-innovation.com/blog/2008/12/08/a-simple-desk-hack/</link>
		<comments>http://www.tierra-innovation.com/blog/2008/12/08/a-simple-desk-hack/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 15:11:20 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tierra-innovation.com/blog/?p=273</guid>
		<description><![CDATA[As a developer I spend most of my day at my desk, designing, coding, emailing and talking on the phone. I work from home on a huge 70's "executive" desk I dragged home from a Freecycle posting and which, after lugging it up to the second floor of my house, I believe is lined with lead and so as a bonus my legs are shielded from cosmic rays It's main feature, other than Supervision protection, is a 5'x3' flat desktop that easily supports my four monitor/three machine setup.]]></description>
			<content:encoded><![CDATA[<p>As a developer I spend most of my day at my desk, designing, coding, emailing and talking on the phone.   I work from home on a huge 70&#8217;s &#8220;executive&#8221; desk I dragged home from a <a href="http://www.freecycle.org/">Freecycle</a> posting and which, after lugging it up to the second floor of my house, I believe is lined with lead and so as a bonus my legs are shielded from cosmic rays  It&#8217;s main feature, other than Supervision protection, is a 5&#8242;x3&#8242; flat desktop that easily supports my four monitor/three machine setup.</p>
<p>Like any desk jockey not wanting to end up walking around when I&#8217;m 70 with T-Rex arms because of carpal tunnel I have my keyboard and mouse in a pull out drawer which frees up most of my desktop  area.  With all that open space I&#8217;ve added a simple feature to the desk that I use all day &#8211; a piece of shiny white <a href="http://en.wikipedia.org/wiki/Masonite">Masonite</a> that covers the top of the desk.  Basically a horizontal whiteboard that always in arms reach.</p>
<p>To use my &#8220;deskboard&#8221; I keep a set of &#8220;Ultra Fine Tip&#8221; Expo markers on hand and use them to take notes, jot down quick to do lists, design UI or just doodle.  The fine tip markers draw lines that are the same size as a felt tip pen so you can pack a lot of detail in a small area.  If I ever needed to save or share a note I could use <a href="http://www.snapter.atiz.com/">Snapter</a>, but so far I haven&#8217;t found the need.</p>
<p>I should patent this&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tierra-innovation.com/blog/2008/12/08/a-simple-desk-hack/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
