<?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>dotvoid.com &#187; locale</title>
	<atom:link href="http://www.dotvoid.com/tag/locale/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotvoid.com</link>
	<description>Experiments and thoughts in PHP and javascript</description>
	<lastBuildDate>Wed, 08 Sep 2010 06:36:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend Framework and locales</title>
		<link>http://www.dotvoid.com/2009/04/zend-framework-and-locales/</link>
		<comments>http://www.dotvoid.com/2009/04/zend-framework-and-locales/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 10:49:00 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[locale]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.dotvoid.com/?p=366</guid>
		<description><![CDATA[Last night I spent a couple of hours with Zend Framework and especially Zend_Form. I discovered, and now also reported as ZF-6175, a bug in Zend_Validate_Float when using a locale with a decimal point other than &#8220;.&#8221;. There are unit tests but none that test Zend_Validate_Float under a different locale.
It is important to know that [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I spent a couple of hours with <a href="http://framework.zend.com">Zend Framework</a> and especially Zend_Form. I discovered, and now also <a href="http://framework.zend.com/issues/browse/ZF-6175">reported as ZF-6175</a>, a bug in Zend_Validate_Float when using a locale with a decimal point other than &#8220;.&#8221;. There are unit tests but none that test Zend_Validate_Float under a different locale.</p>
<p>It is important to know that floats are actually locale aware in PHP. I&#8217;m not sure if that have always been the case. The below code will actually output 10,5 as Swedish use &#8220;,&#8221; as decimal point.</p>
<pre>setlocale(LC_ALL, 'sv_SE.UTF-8');
echo 10.5;</pre>
<p>The test in Zend_Validate_Float looked like</p>
<pre>$locale = localeconv();

$valueFiltered = str_replace($locale['thousands_sep'], '', $valueString);
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);

if (strval(floatval($valueFiltered)) != $valueFiltered) {
  $this-&gt;_error();
  return false;
}</pre>
<p>Under the Swedish locale mentioned above this will result in a comparison between two strings; &#8220;10,5&#8243; and &#8220;10.5&#8243;.</p>
<p>I have proposed the following solution.</p>
<pre>$locale = localeconv();

$valueFiltered = str_replace($locale['thousands_sep'], '', $valueString);
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);

list($num, $dec) = explode('.', $valueFiltered);
if (strval(intval($num)) != $num || strval(intval($dec)) != $dec) {
  $this-&gt;_error();
  return false;
}</pre>
<p>But I just realized that it can be further simplified.</p>
<pre>$locale = localeconv();

$valueFiltered = str_replace($locale['thousands_sep'], '', $valueString);

list($num, $dec) = explode($locale['decimal_point'], $valueFiltered);
if (strval(intval($num)) != $num || strval(intval($dec)) != $dec) {
  $this-&gt;_error();
  return false;
}</pre>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2009/04/zend-framework-and-locales/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2009/04/zend-framework-and-locales/&amp;title=Zend+Framework+and+locales" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2009/04/zend-framework-and-locales/&amp;t=Zend+Framework+and+locales" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2009/04/zend-framework-and-locales/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2009/04/zend-framework-and-locales/&amp;title=Zend+Framework+and+locales&amp;summary=Last%20night%20I%20spent%20a%20couple%20of%20hours%20with%20Zend%20Framework%20and%20especially%20Zend_Form.%20I%20discovered%2C%20and%20now%20also%20reported%20as%20ZF-6175%2C%20a%20bug%20in%20Zend_Validate_Float%20when%20using%20a%20locale%20with%20a%20decimal%20point%20other%20than%20%22.%22.%20There%20are%20unit%20tests%20but%20none%20that%20test%20Zend_Validate_Float%20under%20a%20different%20local&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2009/04/zend-framework-and-locales/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2009/04/zend-framework-and-locales/&amp;title=Zend+Framework+and+locales" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Zend+Framework+and+locales+-+http://b2l.me/wt8x8&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2009/04/zend-framework-and-locales/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
