<?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>willoller.com &#187; Programming</title>
	<atom:link href="http://www.willoller.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.willoller.com</link>
	<description>Learning to match the beat of the Old World man.</description>
	<lastBuildDate>Sat, 28 Aug 2010 00:33:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Ordinal Suffixes in PHP</title>
		<link>http://www.willoller.com/ordinal-suffixes-in-php/</link>
		<comments>http://www.willoller.com/ordinal-suffixes-in-php/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 21:23:55 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.willoller.com/?p=246</guid>
		<description><![CDATA[function ordinalize&#40;$int&#41; &#123; &#160; &#160;//sanity &#160; &#160;$int = &#40;int&#41;$int; &#160; &#160;if&#40;!is_numeric&#40;$int&#41;&#41; return false; &#160; &#160;// You could internationalize here &#160; &#160;$suffixes = array&#40;'th', 'st', 'nd', 'rd'&#41;; &#160; &#160;// Get the number in the tens place &#160; &#160;$tens = substr&#40;$int,-2,1&#41;; &#160; &#160;// All of the numbers 10-19 return 'th' &#160; &#160;if&#40;$tens == 1&#41; return $int.$suffixes&#91;0&#93;; &#160; [...]]]></description>
			<content:encoded><![CDATA[	<div class="code php" style="font-family: monospace;"><br />
<span style="color: #000000; font-weight: bold;">function</span> ordinalize<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$int</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//sanity</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$int</span> = <span style="color: #66cc66;">&#40;</span>int<span style="color: #66cc66;">&#41;</span><span style="color: #0000ff;">$int</span>;<br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/is_numeric"><span style="color: #000066;">is_numeric</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$int</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// You could internationalize here</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$suffixes</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'th'</span>, <span style="color: #ff0000;">'st'</span>, <span style="color: #ff0000;">'nd'</span>, <span style="color: #ff0000;">'rd'</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Get the number in the tens place</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$tens</span> = <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$int</span>,<span style="color: #cc66cc;">-2</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// All of the numbers 10-19 return 'th'</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$tens</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$int</span>.<span style="color: #0000ff;">$suffixes</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Get the number in the ones place</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$cardinal</span> = <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$int</span>,<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// All numbers ending in 1, 2, 3 have special suffixes</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$suffixes</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$cardinal</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$int</span>.<span style="color: #0000ff;">$suffixes</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$cardinal</span><span style="color: #66cc66;">&#93;</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// All remaining numbers end in 'th'</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$int</span>.<span style="color: #0000ff;">$suffixes</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;<br />
<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/ordinal-suffixes-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Textile ol li count bug</title>
		<link>http://www.willoller.com/textile-ol-li-count-bug/</link>
		<comments>http://www.willoller.com/textile-ol-li-count-bug/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 20:10:41 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.willoller.com/?p=201</guid>
		<description><![CDATA[Just hit a bug with the Textile 2.0 library: # Portland, OR # Sanford, FL # Albuquerque, NM # San Diego, CA # Bellingham, WA &#160; Was producing: &#60;ol&#62; &#160; &#160;&#60;li&#62;Portland, OR&#60;/li&#62; &#160; &#160;&#60;li&#62;Sanford, FL&#60;/li&#62; &#160; &#160;&#60;li&#62;Albuquerque, NM&#60;/li&#62; &#160; &#160;&#60;li&#62;San Diego, CA&#160; &#160;&#60;/li&#62; &#60;/ol&#62; &#60;ol&#62; &#160; &#160;&#60;li&#62;Bellingham, WA&#60;/li&#62; &#60;/ol&#62; &#160; Found the solution here: You [...]]]></description>
			<content:encoded><![CDATA[	<p>Just hit a bug with the Textile 2.0 library:</p>
	<div class="code html" style="font-family: monospace;"><br />
# Portland, OR<br />
# Sanford, FL<br />
# Albuquerque, NM<br />
# San Diego, CA<br />
# Bellingham, WA<br />
&nbsp;</div>
	<p>Was producing:</p>
	<div class="code html" style="font-family: monospace;"><br />
&lt;ol&gt;<br />
&nbsp; &nbsp;&lt;li&gt;Portland, OR&lt;/li&gt;<br />
&nbsp; &nbsp;&lt;li&gt;Sanford, FL&lt;/li&gt;<br />
&nbsp; &nbsp;&lt;li&gt;Albuquerque, NM&lt;/li&gt;<br />
&nbsp; &nbsp;&lt;li&gt;San Diego, CA&nbsp; &nbsp;&lt;/li&gt;<br />
&lt;/ol&gt;<br />
&lt;ol&gt;<br />
&nbsp; &nbsp;&lt;li&gt;Bellingham, WA&lt;/li&gt;<br />
&lt;/ol&gt;<br />
&nbsp;</div>
	<p>Found the solution <a href="http://forum.textpattern.com/viewtopic.php?id=24701&#38;p=3">here</a>:</p>
<blockquote>You can work around the problem, by replacing these two lines (in the fList function in /textpattern/lib/classTextile.php):
<div class="code php" style="font-family: monospace;"><br />
<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$text</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">$nextline</span> = <a href="http://www.php.net/next"><span style="color: #000066;">next</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$text</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div>
with:
<div class="code php" style="font-family: monospace;"><br />
<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$text</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$nr</span> =&gt; <span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">$nextline</span> = <a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$text</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$nr</span><span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #0000ff;">$text</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$nr</span><span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#93;</span> : <span style="color: #000000; font-weight: bold;">false</span>;<br />
<br />
&nbsp;</div>
</blockquote>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/textile-ol-li-count-bug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;Cascading&#8221; in CSS</title>
		<link>http://www.willoller.com/cascading-in-css/</link>
		<comments>http://www.willoller.com/cascading-in-css/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 16:58:54 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.blackdogdev.com/?p=94</guid>
		<description><![CDATA[The &#8220;cascading&#8221; in &#8220;Cascading Style Sheets&#8221; has several facets: computed values, inheritance, and specificity. Understanding how these cascades work is an integral part of your css ninja training. Computed Values Many of the values assigned have a unit. Some of these are relative (like em and &#60;span&#62;), and some are absolute (like px and in). [...]]]></description>
			<content:encoded><![CDATA[	<p>The &#8220;cascading&#8221; in &#8220;Cascading Style Sheets&#8221; has several facets: computed values, inheritance, and specificity.  Understanding how these cascades work is an integral part of your css ninja training.</p>
	<h2>Computed Values</h2>
	<p>Many of the values assigned have a unit.  Some of these are <strong>relative</strong> (like <code>em</code> and <code>&lt;span&gt;</code>), and some are <strong>absolute</strong> (like <code>px</code> and <code>in</code>).  Relative values are based on their parents: an element with a width of 50</span> uses the element&#8217;s parent to determine the actual width of the element.</p>
<div style="width:50%;font-family:Georgia,serif;float:left;background:#fcf9ce; border: 1px solid #dfdfdf;padding:4px;margin-bottom:1em;">
width: 50%
<div style="width:50%;float:left;background:#9eee5c;border:1px solid #bababa;padding:2px 4px;">
width: 50%
</div>
</div>
	<p style="clear:left;;">Likewise, if both the parent and child elements&#8217; font-sizes are <code>1.5em</code>, the child&#8217;s actual font size will be larger than the parent&#8217;s.</p>
<div style="border:1px solid #dfdfdf;font-family:Georgia,serif;color:#26838e; font-size:1.5em; background: #eee; margin-bottom:1em;">
1.5em <span style="font-size: 1.5em;">1.5em <span style="font-size: 1.5em;">1.5em </span></span>
</div>
	<p>Absolute values do not change based on their parent values.  These are often obvious: <code>color: red;</code> for example.  Pixel values are absolute, though the actual value displayed by the UA(User Agent) may differ (due to display or text-size settings).</p>
	<h2>Inheritance</h2>
	<p>Inheritance is the passing on of attributes from parents to children.  It works in CSS like this: An element&#8217;s font  color is set to red.  The color for its child elements will also be red (if left unspecified or set to <code>inherit</code>).</p>
<div style="color: red; padding:4px; border: 1px solid #ddd;font-family:Georgia,serif;">
color: red
<div style="padding:4px; border: 1px solid #ddd;">
no color specified
<div style="color: inherit; padding:4px; border: 1px solid #ddd;">
color: inherit
</div>
</div>
</div>
	<h2>Specificity</h2>
	<p>This is how CSS decides between competing styles. Take a look at the following code:</p>
	<div class="code css" style="font-family: monospace;"><br />
p#special_error <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span>; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #6666ff;">.error </span><span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: orange; <span style="color: #66cc66;">&#125;</span><br />
p <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #000000; font-weight: bold;">black</span>; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
	<div class="code html" style="font-family: monospace;"><br />
&lt;p&gt;no class or id&lt;/p&gt;<br />
&lt;p id=&quot;special_error&quot; class=&quot;error&quot;&gt;class and id&lt;/p&gt;<br />
&lt;p class=&quot;error&quot;&gt;p class&lt;/p&gt;<br />
&lt;div class=&quot;error&quot;&gt;div class&lt;/div&gt;<br />
&lt;div id=&quot;special_error&quot;&gt;div id&lt;/div&gt;<br />
&nbsp;</div>
	<p>So what color do the elements end up with?  To answer that question, we need to know how the competing selectors are chosen.</p>
	<p>Each selector has a particular weight outlined in this table:</p>
<table cellspacing="0" cellpadding="0" class="open"><tr>
<th>selector</th><th>weight</th><th>example</th></tr><tr>
<td>id</td><td>100</td><td>#special_error</td></tr><tr class="odd">
<td>class</td><td>10</td><td>.error</td></tr><tr>
<td>element</td><td>1</td><td>p</td></tr></table>
	<p>These weights are all added up and the &#8220;heaviest&#8221; selector set wins.  So using the css above, here are the results:</p>
	<div class="code html" style="font-family: monospace;"><br />
&lt;p&gt;no class or id&lt;/p&gt;&lt;!-- #000000 --&gt;<br />
&lt;p id=&quot;special_error&quot; class=&quot;error&quot;&gt;class and id&lt;/p&gt;&lt;!-- red --&gt;<br />
&lt;p class=&quot;error&quot;&gt;p class&lt;/p&gt;&lt;!-- orange --&gt;<br />
&lt;div class=&quot;error&quot;&gt;div class&lt;/div&gt;&lt;!-- orange --&gt;<br />
&lt;div id=&quot;special_error&quot;&gt;div id&lt;/div&gt;&lt;!-- inherits --&gt;<br />
&nbsp;</div>
	<h3>Links</h3>
	<p><a href="http://www.w3.org/TR/REC-CSS2/cascade.html">w3.org</a><br />
<a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets">wikipedia</a><br />
<a href="http://htmlhelp.com/reference/css/structure.html">htmlhelp</a></p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/cascading-in-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Counting Characters php vs javascript</title>
		<link>http://www.willoller.com/counting-characters-php-vs-javascript/</link>
		<comments>http://www.willoller.com/counting-characters-php-vs-javascript/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 04:13:05 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.willoller.com/?p=159</guid>
		<description><![CDATA[On a recent project, an issue cropped up where we were exporting xml reports to a third party, who had rules about line lengths in Description fields. So, I wrote up a quick-and-dirty character counter for the description field so the client can keep their descriptions under the 1500-word limit. Here&#8217;s how it was done: [...]]]></description>
			<content:encoded><![CDATA[	<p>On a recent project, an issue cropped up where we were exporting xml reports to a third party, who had rules about line lengths in Description fields.</p>
	<p>So, I wrote up a quick-and-dirty character counter for the description field so the client can keep their descriptions under the 1500-word limit.</p>
	<p>Here&#8217;s how it was done:</p>
	<div class="code php" style="font-family: monospace;"><br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$fdata</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'description'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$errors</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;You must enter a Description&quot;</span>;<br />
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fdata</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'description'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> &gt; <span style="color: #cc66cc;">1500</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$len</span> = <a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fdata</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'description'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #0000ff;">$errors</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Descriptions are limited to 1500 characters ($len)&quot;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
	<p>Now the html and javascript:</p>
	<div class="code html" style="font-family: monospace;"><br />
&lt;li class=&quot;description&quot;&gt;<br />
&nbsp; &nbsp;&lt;label for=&quot;htmlarea&quot; class=&quot;required&quot;&gt;Description *&lt;/label&gt;<br />
&nbsp; &nbsp;&lt;textarea name=&quot;description&quot; id=&quot;htmlarea&quot; cols=&quot;80&quot; rows=&quot;20&quot; class=&quot;textarea&quot;&gt;&lt; ?= $ff['description'] ?&gt;&lt;/textarea&gt;<br />
&nbsp; &nbsp;&lt;p class=&quot;hint&quot; id=&quot;desc_char_count&quot;&gt;1500 character limit&lt;/p&gt;<br />
&lt;/li&gt;<br />
&nbsp;</div>
	<div class="code javascript" style="font-family: monospace;"><br />
$<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#htmlarea'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">keyup</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> charLength = $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">val</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">length</span>;<br />
&nbsp; &nbsp; &nbsp; $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#desc_char_count'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>charLength + <span style="color: #3366CC;">' of 1500 characters used'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">val</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">length</span> &gt; <span style="color: #CC0000;">1500</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#desc_char_count'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'positive'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'negative'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'&lt;strong&gt;You have '</span> + $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">val</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">length</span> + <span style="color: #3366CC;">' characters. You may only have up to 1500 characters.&lt;/strong&gt;'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#desc_char_count'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'positive'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'negative'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#htmlarea'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">keyup</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div>
	<p>All was working well, except I underestimated the descriptions. The next morning, the thing was broken. The php side was kicking validation errors (&#8220;over 1500 characters&#8221;), while the javascript was counting a mere 1480. Why?</p>
	<p>Turns out the data was full of bullets and other multibyte characters. To make the counts match, I needed multibyte-safe php:</p>
	<div class="code php" style="font-family: monospace;"><br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$fdata</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'description'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$errors</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;You must enter a Description&quot;</span>;<br />
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mb_strlen"><span style="color: #000066;">mb_strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fdata</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'description'</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #ff0000;">'UTF-8'</span><span style="color: #66cc66;">&#41;</span> &gt; <span style="color: #cc66cc;">1500</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$len</span> = <a href="http://www.php.net/mb_strlen"><span style="color: #000066;">mb_strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$fdata</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'description'</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #ff0000;">'UTF-8'</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #0000ff;">$errors</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Descriptions are limited to 1500 characters ($len)&quot;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
	<p>Hooray! Now the counts match!</p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/counting-characters-php-vs-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can&#8217;t wait for Resig&#8217;s new boo&#8230;</title>
		<link>http://www.willoller.com/cant-wait-for-resigs-new-boo/</link>
		<comments>http://www.willoller.com/cant-wait-for-resigs-new-boo/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 05:30:55 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tweets]]></category>

		<guid isPermaLink="false">http://www.willoller.com/cant-wait-for-resigs-new-boo/</guid>
		<description><![CDATA[Can&#8217;t wait for Resig&#8217;s new book. http://jsninja.com/]]></description>
			<content:encoded><![CDATA[	<p>Can&#8217;t wait for Resig&#8217;s new book. <a href="http://jsninja.com/">http://jsninja.com/</a></p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/cant-wait-for-resigs-new-boo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Firebug to Update A Huge Form</title>
		<link>http://www.willoller.com/use-firebug-to-update-a-huge-form/</link>
		<comments>http://www.willoller.com/use-firebug-to-update-a-huge-form/#comments</comments>
		<pubDate>Tue, 13 May 2008 04:43:08 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.willoller.com/?p=38</guid>
		<description><![CDATA[Had a problem recently where I had to update hundreds of input fields within a shopping cart, setting prices of product variants from $200 to $49. They were named in sequence: ... &#60;input name=&#34;vs[1667][price]&#34; value=&#34;200&#34; /&#62; &#60;input name=&#34;vs[1668][price]&#34; value=&#34;200&#34; /&#62; &#60;input name=&#34;vs[1669][price]&#34; value=&#34;200&#34; /&#62; ... &#160; So I busted out the command line in Firebug. [...]]]></description>
			<content:encoded><![CDATA[	<p>Had a problem recently where I had to update hundreds of input fields within a shopping cart, setting prices of product variants from $200 to $49.</p>
	<p>They were named in sequence:</p>
	<div class="code javascript" style="font-family: monospace;"><br />
...<br />
&lt;input <span style="color: #000066;">name</span>=<span style="color: #3366CC;">&quot;vs[1667][price]&quot;</span> value=<span style="color: #3366CC;">&quot;200&quot;</span> /&gt;<br />
&lt;input <span style="color: #000066;">name</span>=<span style="color: #3366CC;">&quot;vs[1668][price]&quot;</span> value=<span style="color: #3366CC;">&quot;200&quot;</span> /&gt;<br />
&lt;input <span style="color: #000066;">name</span>=<span style="color: #3366CC;">&quot;vs[1669][price]&quot;</span> value=<span style="color: #3366CC;">&quot;200&quot;</span> /&gt;<br />
...<br />
<br />
&nbsp;</div>
	<p>So I busted out the command line in Firebug.<br />
<div class="code javascript" style="font-family: monospace;"><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i=<span style="color: #CC0000;">0</span>; i&amp;lt;<span style="color: #CC0000;">10000</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>document.<span style="color: #006600;">productvariantsform</span>.<span style="color: #006600;">elements</span><span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;vs[&quot;</span> + i + <span style="color: #3366CC;">&quot;][price]&quot;</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; document.<span style="color: #006600;">productvariantsform</span>.<span style="color: #006600;">elements</span><span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;vs[&quot;</span> + i + <span style="color: #3366CC;">&quot;][price]&quot;</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">value</span> = <span style="color: #3366CC;">&quot;49.00&quot;</span>;<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
 but all I got were &#8220;has no properties&#8221; errors.</p>
	<p>I got in touch with my local Javascript guru who helped me come up with some code that did work:<br />
<div class="code javascript" style="font-family: monospace;"><br />
<span style="color: #003366; font-weight: bold;">var</span> frm = document.<span style="color: #006600;">productvariantsform</span>;<br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i=<span style="color: #CC0000;">0</span>; i &lt; frm.<span style="color: #006600;">elements</span>.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>frm.<span style="color: #006600;">elements</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #000066;">name</span>.<span style="color: #006600;">match</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/\<span style="color: #66cc66;">&#91;</span>price\<span style="color: #66cc66;">&#93;</span>$/</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>frm.<span style="color: #006600;">elements</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; frm.<span style="color: #006600;">elements</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">value</span> = <span style="color: #3366CC;">&quot;49.00&quot;</span>;<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
	<p>This saved literally hours of [TAB][TAB][TAB][TAB][Ctrl+V].<br />
Thank you Firebug!</code></p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/use-firebug-to-update-a-huge-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Textile &#8211; Humane Text Generator</title>
		<link>http://www.willoller.com/textile-humane-text-generator/</link>
		<comments>http://www.willoller.com/textile-humane-text-generator/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 23:38:18 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[textile]]></category>

		<guid isPermaLink="false">http://www.blackdogdev.com/?p=85</guid>
		<description><![CDATA[Blogs, bulletin boards, community sites&#8212;the whole web2.0&#169; rely on the same thing: user input. On the web, user input usually means HTML. Some simple HTML is easy to learn, like &#60;b&#62;bold&#60;/b&#62; and &#60;i&#62;italics&#60;/i&#62;, but other techniques (like links, lists, and blockquotes) can be a little more daunting. For a site owner, badly written HTML can [...]]]></description>
			<content:encoded><![CDATA[	<p>Blogs, bulletin boards, community sites&#8212;the whole web2.0&#169; rely on the same thing: user input.  On the web, user input usually means HTML.</p>
	<p>Some simple HTML is easy to learn, like <code>&lt;b&gt;bold&lt;/b&gt;</code> and <code>&lt;i&gt;italics&lt;/i&gt;</code>, but other techniques (like links, lists, and blockquotes) can be a little more daunting.  For a site owner, badly written HTML can break a site.</p>
	<p>So what are you, the site owner, to do? You shouldn&#8217;t have to learn all about HTML yourself (unless you want to), and can&#8217;t force your readers to learn HTML just to post feedback.</p>
	<p>There are a few apps that can help people &#8220;mark up&#8221; text, and these work well, in general.  The drawbacks are they can be bulky or hard to use, and suffer from technical issues including lack of browser support and buggy performance.  These drawbacks make them more suited for intranets and administrators, and less suited for the rest of the World-Wide Web.</p>
	<p>Lately, another method has resurfaced: server-side markup generators.  They work behind the scenes to change easier markup into HTML.  Anyone familiar with bulletin boards will know about BBCode; it generally worked like this:</p>
<code>[b]Bold[/b], [i]italics[/i],  [u]underlined[/u].</code>
will produce
<strong>bold</strong>, <em>italics</em>, <u>underlined</u>.
	<p>But this is not really enough.  Its really just HTML with  replaced with [ and ].  BBCode also can&#8217;t do some of the the advanced things (lists, blockquotes) HTML still has to offer.</p>
	<h3>Along came Textile</h3>
	<p>Here at Black Dog, we use Textile to solve this problem.  It is a server-side markup generator, like BBCode, but it has all of the bells and whistles you need to produce good HTML.  Instead of using HTML-like syntax, it uses easy-to-remember symbols.  The best part is, the symbols make sense before they are turned into HTML.</p>
<code>&lt;strong&gt;bold&lt;/strong&gt;, &lt;em&gt;italics&lt;/em&gt;.</code>
becomes
<strong>bold</strong>, <em>italics</em>.
	<p>Textile also handles lists and sublists, ordered and unordered:</p>
	<div class="code html" style="font-family: monospace;"><br />
* An item in an unordered list<br />
* Another unordered list item<br />
** Second Level item<br />
** Second Level item<br />
*** Third Level<br />
<br />
# An item in a numbered (ordered) list<br />
# Another item<br />
## Second level item<br />
&nbsp;</div>
	<p>It also helps you out with the little things: double quotes and single quotes are made &#8220;curly,&#8221; and dashes&#8212;I love those helpful little guys&#8212;are made into their correct typographical charaters.</p>
	<p>The best part: Textile doesn&#8217;t ruin good HTML, so you can mix-and-match HTML and Textile if you want to, but it quietly throws out bad or broken HTML so your content stays nice, clean, and readable.</p>
	<h3>Everybody wins</h3>
	<p>As a site owner, you have some additional protection against buggy HTML from users or even yourself.  As a user, you can make make your text <em>stand out</em> without learning a bunch of HTML tags.  As a reader, the web will be a little easier on the eyes.</p>
	<h3>Further Information</h3>
	<p><a href="http://en.wikipedia.org/wiki/Textile_(markup_language)">Textile&#8217;s entry on Wikipedia</a><br />
<a href="http://hobix.com/textile/">Advanced Textile reference (hobix.com)</a><br />
<a href="http://www.textpattern.com/">Textpattern (CMS built with Textile)</a><br />
<a href="http://www.textism.com/">Dean Allen&#8217;s home page (Creator of Textile and Textpattern)</a></p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/textile-humane-text-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is Vista forcing me to upgrade iTunes?</title>
		<link>http://www.willoller.com/is-vista-forcing-me-to-upgrade-itunes/</link>
		<comments>http://www.willoller.com/is-vista-forcing-me-to-upgrade-itunes/#comments</comments>
		<pubDate>Tue, 01 Jan 2008 23:05:56 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Podcasts]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.willoller.com/is-vista-forcing-me-to-upgrade-itunes/</guid>
		<description><![CDATA[Okay, maye I&#8217;m jsut being paranoid or it&#8217;s a big coincidence, but this seems to be a consistent event.&#160; I&#8217;m updating my iPod with iTunes, and everything is tooling along nicely.&#160; Podcasts are updating and downloading, the store is working, and the music is playing.&#160; Perfect. Then, an update becomes available (this time 7.5).&#160; Now, [...]]]></description>
			<content:encoded><![CDATA[	<p>Okay, maye I&#8217;m jsut being paranoid or it&#8217;s a big coincidence, but this seems to be a consistent event.&nbsp; I&#8217;m updating my iPod with iTunes, and everything is tooling along nicely.&nbsp; Podcasts are updating and downloading, the store is working, and the music is playing.&nbsp; Perfect.</p>
	<p>Then, an update becomes available (this time 7.5).&nbsp; Now, before downloading the update, iTunes crashes every five minutes with the Not-Vista&#8217;s-Fault error &#8220;caused by iTunes&#8221;.  In addition, the iTunes store and my podcast downloads start timing out.</p>
	<p>This same pattern happens when using Firefox and AVG: everything fine then crash city once an update becomes available.</p>
	<p>I wouldn&#8217;t put it past Vista to say &#8220;Fine.&nbsp; If you don&#8217;t update your software we&#8217;ll <span style="font-style: italic;">make</span> you do it.</p>
	<p>Anyone else on Vista having this experience?</p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/is-vista-forcing-me-to-upgrade-itunes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Montoya and the DOM sittin&#8217; in a tree</title>
		<link>http://www.willoller.com/montoya-and-the-dom-sittin-in-a-tree/</link>
		<comments>http://www.willoller.com/montoya-and-the-dom-sittin-in-a-tree/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 01:28:15 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.willoller.com/montoya-and-the-dom-sittin-in-a-tree/</guid>
		<description><![CDATA[Makes a great point about syntax. Plus, I&#8217;m blogging using Flock.&#160; How neat. I used to hate Javascript’s syntax. I still do, but to a lesser extent. But I know where most of it came from. And I don’t know what your programming experience is, but C, PHP, etc. all use “function,” so it is [...]]]></description>
			<content:encoded><![CDATA[	<p>Makes a great point about syntax.<br />
Plus, I&#8217;m blogging using Flock.&nbsp; How neat.<br />
<blockquote cite="http://www.christianmontoya.com/2007/12/10/how-i-learned-to-stop-programming-and-love-the-dom/"></p>
	<p>I used to hate Javascript’s syntax. I still do, but to a lesser extent. But I know where most of it came from. And I don’t know what your programming experience is, but C, PHP, etc. all use “function,” so it is totally natural to me.But I’ve grown up about syntax, and I’ve realized that while every programmer wants a language with beautiful syntax, arguing/worrying/complaining about syntax is stupid. I don’t care if it’s def or function, class or object, import or include. I care about what I can do with the language, and that’s what this is all about.</blockquote><cite cite="http://www.christianmontoya.com/2007/12/10/how-i-learned-to-stop-programming-and-love-the-dom/"><a href="http://www.christianmontoya.com/2007/12/10/how-i-learned-to-stop-programming-and-love-the-dom/">How I learned to stop programming and love the DOM | The Montoya Herald</a></cite><br />
<p style="text-align: right; font-size: 8px">Blogged with <a href="http://www.flock.com/blogged-with-flock" title="Flock" target="_new">Flock</a></p></p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/montoya-and-the-dom-sittin-in-a-tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails &#8211; Is this love?</title>
		<link>http://www.willoller.com/ruby-on-rails-is-this-love/</link>
		<comments>http://www.willoller.com/ruby-on-rails-is-this-love/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 05:18:44 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.willoller.com/ruby-on-rails-is-this-love/</guid>
		<description><![CDATA[I installed InstantRails on my iPod (so that I can work/save anywhere without paying for a server, of course). I am writing a tiny app based on 4 Days on Rails. I am planning my exposure to this incredible framework will give me some serious inspiration for Black Dog&#8217;s PHP framework. These plans are well-laid. [...]]]></description>
			<content:encoded><![CDATA[	<p>I installed <a href="http://instantrails.rubyforge.org/wiki/wiki.pl">InstantRails</a> on my iPod (so that I can work/save anywhere without paying for a server, of course).  I am writing a tiny app based on <a href="http://rails.homelinux.org/">4 Days on Rails</a>.</p>
	<p>I am planning my exposure to this incredible framework will give me some serious inspiration for Black Dog&#8217;s PHP framework.  These plans are well-laid.</p>
	<p>As for love, I&#8217;ll let you know.  </p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/ruby-on-rails-is-this-love/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
