<?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; code</title>
	<atom:link href="http://www.willoller.com/tags/code/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>Thu, 02 Feb 2012 23:34:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.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[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></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>Combining css selectors</title>
		<link>http://www.willoller.com/combining-css-selectors/</link>
		<comments>http://www.willoller.com/combining-css-selectors/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 16:37:35 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.blackdogdev.com/?p=89</guid>
		<description><![CDATA[We often come across css code in dire need of optimization (details have been changed to protect the guilty), and shows a misunderstanding about the power of css: h1 &#123; &#160; &#160;font-family: Arial, Helvetica, Geneva, Swiss,&#160; sans-serif; &#160; &#160;font-size: 18px; &#160; &#160;font-style: normal; &#160; &#160;font-weight: bold; &#160; &#160;text-transform: none; &#160; &#160;color: #7D0126; &#160; &#160;margin-bottom: 2px; [...]]]></description>
			<content:encoded><![CDATA[	<p>We often come across css code in dire need of optimization (details have been changed to protect the guilty), and shows a misunderstanding about the power of css:</p>
	<div class="code css" style="font-family: monospace;"><br />
h1 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 18px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-transform</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #7D0126;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 2px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-bottom</span>: 0px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 26px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 12px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-top</span>: 0px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h2 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 16px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-transform</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #7D0126;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 2px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-bottom</span>: 0px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 24px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-top</span>: 0px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h3 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 14px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">italic</span>;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 20px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #6B917C;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 7px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h4 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 12px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 18px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 6px;<br />
<span style="color: #66cc66;">&#125;</span><br />
p <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 11px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 17px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 6px;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* It keeps going like this but we're going to stop here */</span><br />
<br />
&nbsp;</div>
	<p>As you can see, several properties are repeated across elements.<br />
These can (and should) be consolidated.</p>
	<p>Let&#8217;s consolidate them first by applying very common properties to the <code>body</code> element:</p>
	<div class="code css" style="font-family: monospace;"><br />
body <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 11px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 15px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #cc66cc;">600</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-variant</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-transform</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-decoration</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-align</span>: <span style="color: #000000; font-weight: bold;">left</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">white-space</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">000000</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
h1 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 18px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #7D0126;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 2px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-bottom</span>: 0px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 26px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 12px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-top</span>: 0px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h2 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 16px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #7D0126;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 2px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-bottom</span>: 0px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 24px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding-top</span>: 0px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h3 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 14px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">italic</span>;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 20px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #6B917C;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 7px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h4 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 12px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 18px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 6px;<br />
<span style="color: #66cc66;">&#125;</span><br />
p <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 17px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 11px;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
	<p>Okay, now we see a lot of repetion is still happening here.  Much of this repetition can be removed by using the comma (,) selector, which allows you to make lists of elements:</p>
	<div class="code css" style="font-family: monospace;"><br />
body <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 11px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 17px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #cc66cc;">600</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-variant</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-transform</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-decoration</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-align</span>: <span style="color: #000000; font-weight: bold;">left</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">white-space</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">000000</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
h1, h2, h3, h4, p <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding</span>: 0px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h1, h2 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 16px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #7D0126;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 2px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 16px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 24px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h1 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 18px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 26px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 12px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h3 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 14px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">italic</span>;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 20px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #6B917C;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 7px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h4 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 12px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: 18px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 6px;<br />
<span style="color: #66cc66;">&#125;</span><br />
p <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 6px;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
	<p>There is a pattern to the font-size, margin-height, and line-heights.  We will now use this to our advantage to make life even easier.</p>
	<div class="code css" style="font-family: monospace;"><br />
body <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-family</span>: Arial, Helvetica, Geneva, Swiss,&nbsp; <span style="color: #993333;">sans-serif</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 11px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #cc66cc;">600</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-variant</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-transform</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-decoration</span>: <span style="color: #993333;">none</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">text-align</span>: <span style="color: #000000; font-weight: bold;">left</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">white-space</span>: <span style="color: #993333;">normal</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">000000</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
h1, h2, h3, h4, p <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin</span>: 0px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">padding</span>: 0px;<br />
&nbsp; &nbsp;line-<span style="color: #000000; font-weight: bold;">height</span>: <span style="color: #cc66cc;">150</span>%;&nbsp; <span style="color: #808080; font-style: italic;">/* A good approximation */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: <span style="color: #cc66cc;">0</span><span style="color: #6666ff;">.5em </span><span style="color: #808080; font-style: italic;">/* another approximation */</span><br />
<span style="color: #66cc66;">&#125;</span><br />
h1, h2 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 16px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #7D0126;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 2px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h1 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 18px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-top</span>: 12px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h3 <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-size</span>: 14px;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">font-style</span>: <span style="color: #993333;">italic</span>;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">color</span>: #6B917C;<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">margin-bottom</span>: 7px;<br />
<span style="color: #66cc66;">&#125;</span><br />
h4 <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span>: 12px; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp;</div>
	<p>With just a few basic css selectors, this code was cut in half.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/combining-css-selectors/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[php]]></category>
		<category><![CDATA[Programming]]></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[css]]></category>
		<category><![CDATA[Programming]]></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[php]]></category>
		<category><![CDATA[php programming]]></category>
		<category><![CDATA[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>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>Typography on the Web</title>
		<link>http://www.willoller.com/typography-on-the-web/</link>
		<comments>http://www.willoller.com/typography-on-the-web/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 16:28:29 +0000</pubDate>
		<dc:creator>will</dc:creator>
				<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://www.blackdogdev.com/?p=88</guid>
		<description><![CDATA[Typography on the web resembles print typography only superficially. There are important limitations with units, fonts, styles, and effects. In web design, there are a few common units used for setting the sizes of elements. They are: percentage em em is a multiplier applied to the current font size: 1em is equal to the current [...]]]></description>
			<content:encoded><![CDATA[	<p><strong>Typography on the web resembles print typography only superficially.</strong> There are important limitations with units, fonts, styles, and effects.</p>
	<p>In web design, there are a few common units used for setting the sizes of elements.  They are:</p>
<table>
<tr>
  <th><span></th>
  <td>percentage</td>
</tr>
<tr>
  <th>em</th>
  <td>em is a multiplier applied to the current font size: 1em is equal to the current font size, and 2em means 2 times the current font size.</td>
</tr>
<tr>
  <th>pt</th>
  <td>points, 1 pt is the same as 1/72 inch</td>
</tr>
<tr>
  <th>px</th>
  <td>pixels, a dot on the computer screen</td>
</tr>
</table>
	<p>For a full list, see <a href="http://www.w3schools.com/css/css_units.asp">W3Schools</a>.</p>
	<p>The rub is that all of these units are converted into pixels for display on the screen. Each OS and browser use a slightly different algorithm for this conversion; generally 9pt=12px but that will vary depending on the settings of the individual computer.</p>
	<p>These differences are relatively minor (1 or 2 pixels) when applied to text alone, but can become unbearable when specifying line height, letter spacing, word spacing, etc.  When displayed on-screen, extra care must be taken to consider these uncontrollable discrepancies in font rendering algorithms.</p>
	<p>Therefore, the following css units are generally used by Black Dog Studios for setting font sizes on fixed-width layouts:</p>
	<p>font-size: <strong>px</strong><br />
line-height: <strong></span></strong><br />
letter-spacing: <strong>em</strong><br />
word-spacing: <strong>em</strong><br />
margins: <strong>px</strong> (sometimes em)<br />
padding: <strong>px</strong> (rarely em)</p>
	<p>We of course do our best to match design comps which use points or an unknown unit; however <em>Black Dog Studios cannot guarantee pixel-perfect (or sub-pixel-perfect) accuracy when making these conversions</em>.</p>
	<p>The following links are to articles and tools related to the conversion between px, pt, em, and %.</p>
	<p><ul><br />
<li><a href="http://sureshjain.wordpress.com/2007/07/06/53/"><br />

http://sureshjain.wordpress.com/2007/07/06/53/</a></li></p>

	<p><li><a href="http://www.faqts.com/knowledge_base/view.phtml/aid/19491">http://www.faqts.com/knowledge_base/view.phtml/aid/19491</a></li></p>
	<p><li><a href="http://archivist.incutio.com/viewlist/css-discuss/78195">http://archivist.incutio.com/viewlist/css-discuss/78195</a></li></p>
	<p><li><a href="http://riddle.pl/emcalc/">http://riddle.pl/emcalc/</a></li></p>
	<p><li><a href="http://www.jerekdain.com/fontconversion.html">http://www.jerekdain.com/fontconversion.html</a></li><br />
</ul></p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.willoller.com/typography-on-the-web/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

