<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'PHP month days options'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Thu, 20 Jun 2013 11:47:32 GMT</pubDate>
<item>
<title>joefoo said on 9/27/06</title>
<link>http://snipplr.com/view/1230/php-month-days-options/</link>
<description><![CDATA[ <pre><code>if( strlen( $x ) == 1 ) $x = '0' . $x;
</code></pre>

<p>You were looking for this;</p>

<pre><code>sprintf('%02d', $x)
</code></pre>

<p>In fact some further use of sprintf it reduces to</p>

<pre><code>function getDayOptions( $selected )
{
    $options = '';
    $optmask = '<option value="%1$02d"%2$s>%1$02d</option>';

    for( $x = 1; $x < 32; $x++ )
    {
        $selstr = $x == $selected ? ' selected="selected"' : '';
        $options .= sprintf($optmask, $x, $selstr);
    }

    return $options;
}
</code></pre>
 ]]></description>
<pubDate>Wed, 27 Sep 2006 15:35:44 GMT</pubDate>
<guid>http://snipplr.com/view/1230/php-month-days-options/</guid>
</item>
</channel>
</rss>