<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: PHP: Multi-byte-safe number_format function</title>
	<atom:link href="http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/</link>
	<description>Open Source, The Web, And German-American Oddities</description>
	<pubDate>Fri, 21 Nov 2008 20:10:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Fred</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156620</link>
		<dc:creator>Fred</dc:creator>
		<pubDate>Fri, 30 May 2008 07:33:09 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156620</guid>
		<description>Wladimir, thank you for your comment. nothingEverEasy++ While I don't think the Japanese people will chop our heads off for three-digit-grouping their numbers, this aspect indeed adds to the annoyance of number_format. :(</description>
		<content:encoded><![CDATA[<p>Wladimir, thank you for your comment. nothingEverEasy++ While I don&#8217;t think the Japanese people will chop our heads off for three-digit-grouping their numbers, this aspect indeed adds to the annoyance of number_format. <img src='http://fredericiana.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wladimir Palant</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156616</link>
		<dc:creator>Wladimir Palant</dc:creator>
		<pubDate>Fri, 30 May 2008 07:24:15 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156616</guid>
		<description>Actually, number_format is also broken in another aspect - it assumes that you always want to group three digits together. Now for some locales that isn't what you want to do, see http://blogs.msdn.com/oldnewthing/archive/2006/04/17/577483.aspx

Now you can have fun fixing Japanese locale on AMO.</description>
		<content:encoded><![CDATA[<p>Actually, number_format is also broken in another aspect &#8211; it assumes that you always want to group three digits together. Now for some locales that isn&#8217;t what you want to do, see <a href="http://blogs.msdn.com/oldnewthing/archive/2006/04/17/577483.aspx" rel="nofollow">http://blogs.msdn.com/oldnewthing/archive/2006/04/17/577483.aspx</a></p>
<p>Now you can have fun fixing Japanese locale on AMO.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fred</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156507</link>
		<dc:creator>Fred</dc:creator>
		<pubDate>Thu, 29 May 2008 22:23:42 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156507</guid>
		<description>@Robert: another thing: that comment you linked to was actually the hint that pointed me into the right direction for figuring out where these question marks came from.

When I googled for a workaround though, I couldn't find one (except possibly whole frameworks that also handle this correctly) so I just wrote a little function myself.</description>
		<content:encoded><![CDATA[<p>@Robert: another thing: that comment you linked to was actually the hint that pointed me into the right direction for figuring out where these question marks came from.</p>
<p>When I googled for a workaround though, I couldn&#8217;t find one (except possibly whole frameworks that also handle this correctly) so I just wrote a little function myself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fred</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156497</link>
		<dc:creator>Fred</dc:creator>
		<pubDate>Thu, 29 May 2008 21:36:50 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156497</guid>
		<description>@Robert, this is correct. The manual does not claim this function being multi-byte safe. However, it's one of the functions where you would surely hope it was :)

@Gijs: oh, thanks for pointing this out. I guess I could get around this by using more exceptional placeholders (like @ and ~), I'm going to do this now but that's not quite as universal as I'd like it to be. When I looked at the preg_replace manual page though I didn't find information so far on how it does the string replacements, so I may have to test that.</description>
		<content:encoded><![CDATA[<p>@Robert, this is correct. The manual does not claim this function being multi-byte safe. However, it&#8217;s one of the functions where you would surely hope it was <img src='http://fredericiana.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>@Gijs: oh, thanks for pointing this out. I guess I could get around this by using more exceptional placeholders (like @ and ~), I&#8217;m going to do this now but that&#8217;s not quite as universal as I&#8217;d like it to be. When I looked at the preg_replace manual page though I didn&#8217;t find information so far on how it does the string replacements, so I may have to test that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jm one</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156481</link>
		<dc:creator>jm one</dc:creator>
		<pubDate>Thu, 29 May 2008 20:49:55 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156481</guid>
		<description>Robert:
Yet again, due to the nature of the functions very purpose, it should be multi-byte save. I guess that might be source of the wrong assumption that it is. Or as Frederic put it: it s kind of ironic that it isn't.</description>
		<content:encoded><![CDATA[<p>Robert:<br />
Yet again, due to the nature of the functions very purpose, it should be multi-byte save. I guess that might be source of the wrong assumption that it is. Or as Frederic put it: it s kind of ironic that it isn&#8217;t.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gijs</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156454</link>
		<dc:creator>Gijs</dc:creator>
		<pubDate>Thu, 29 May 2008 19:17:42 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156454</guid>
		<description>Actually, your function does not work properly. This is because str_replace processes your array one item at a time. That is to say, first it will search the entire string for all occurrences of the first item, and replace them, then it will search this string for all occurrences of the second item, and replace those.

So, if localeconv() gives you back array(',', '.'), which is what it should do for the Dutch locale, for instance - then the result of 1234.56 becomes 1.234.56, whereas it should be 1.234,56 . This is because at first the dots are changed to commas, and then all commas to dots.

In javascript at least, you can call .replace with a regexp (matching both items) and a function parameter, so you could do something like:

"1,234.56".replace(/[,.]/g, function(match) { return (match == ".") ? "," : "."; } );

which does what you want. I'm not sure if preg_replace or friends have similar functionality in php, I'm not very familiar with it.</description>
		<content:encoded><![CDATA[<p>Actually, your function does not work properly. This is because str_replace processes your array one item at a time. That is to say, first it will search the entire string for all occurrences of the first item, and replace them, then it will search this string for all occurrences of the second item, and replace those.</p>
<p>So, if localeconv() gives you back array(&#8217;,', &#8216;.&#8217;), which is what it should do for the Dutch locale, for instance &#8211; then the result of 1234.56 becomes 1.234.56, whereas it should be 1.234,56 . This is because at first the dots are changed to commas, and then all commas to dots.</p>
<p>In javascript at least, you can call .replace with a regexp (matching both items) and a function parameter, so you could do something like:</p>
<p>&#8220;1,234.56&#8243;.replace(/[,.]/g, function(match) { return (match == &#8221;.&#8221;) ? &#8221;,&#8221; : &#8221;.&#8221;; } );</p>
<p>which does what you want. I&#8217;m not sure if preg_replace or friends have similar functionality in php, I&#8217;m not very familiar with it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eevee</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156438</link>
		<dc:creator>Eevee</dc:creator>
		<pubDate>Thu, 29 May 2008 18:17:06 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156438</guid>
		<description>Good grief PHP is a mess.  You even have to feed it the separators yourself?</description>
		<content:encoded><![CDATA[<p>Good grief PHP is a mess.  You even have to feed it the separators yourself?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Accettura</title>
		<link>http://fredericiana.com/2008/05/29/php-multi-byte-safe-number_format-function/#comment-156429</link>
		<dc:creator>Robert Accettura</dc:creator>
		<pubDate>Thu, 29 May 2008 17:48:04 +0000</pubDate>
		<guid isPermaLink="false">http://fredericiana.com/?p=1287#comment-156429</guid>
		<description>I ran across a similar issue before as well.  It should be noted the function was never designated as multi-byte safe, so it shouldn't be assumed to be.

It's been documented before too:
http://us2.php.net/manual/en/function.number-format.php#69192</description>
		<content:encoded><![CDATA[<p>I ran across a similar issue before as well.  It should be noted the function was never designated as multi-byte safe, so it shouldn&#8217;t be assumed to be.</p>
<p>It&#8217;s been documented before too:<br />
<a href="http://us2.php.net/manual/en/function.number-format.php#69192" rel="nofollow">http://us2.php.net/manual/en/function.number-format.php#69192</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
