setlocale and currency_symbol

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rooster242
Forum Newbie
Posts: 18
Joined: Thu Aug 31, 2006 6:23 pm

setlocale and currency_symbol

Post by Rooster242 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


for some reason when i use setlocale for certain(most) regions I get a ? for currency_symbol.  i'm pretty sure this isn't a problem with my server or it's os because a created a test page with this:

Code: Select all

<?php

$loc = setlocale( LC_ALL, "eng" );
echo( setlocale( LC_ALL, 0 ) );

echo( "<br /><br />" );

$locInfo = localeconv();
echo( var_dump( $locInfo ) );

echo( "<br /><br />" );

echo( $locInfo[ 'currency_symbol' ] );

?>
which correctly outputs:

Code: Select all

English_United Kingdom.1252

array(18) { ["decimal_point"]=> string(1) "." ["thousands_sep"]=> string(1) "," ["int_curr_symbol"]=> string(3) "GBP" ["currency_symbol"]=> string(1) "£" ["mon_decimal_point"]=> string(1) "." ["mon_thousands_sep"]=> string(1) "," ["positive_sign"]=> string(0) "" ["negative_sign"]=> string(1) "-" ["int_frac_digits"]=> int(2) ["frac_digits"]=> int(2) ["p_cs_precedes"]=> int(1) ["p_sep_by_space"]=> int(0) ["n_cs_precedes"]=> int(1) ["n_sep_by_space"]=> int(0) ["p_sign_posn"]=> int(3) ["n_sign_posn"]=> int(3) ["grouping"]=> array(1) { [0]=> int(3) } ["mon_grouping"]=> array(1) { [0]=> int(3) } }

£
but i have another site on the same server that outputs a question mark for currency_symbol and i can't for the life of me figure out why. any clues?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Maybe it's using a charset without £
Rooster242
Forum Newbie
Posts: 18
Joined: Thu Aug 31, 2006 6:23 pm

Post by Rooster242 »

volka wrote:Maybe it's using a charset without £
that's what i was thinking but i'm using the same charset on my test page and it works fine.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How are you setting the character sets in both pages? Is it not possible to use the &pound; entity?
Rooster242
Forum Newbie
Posts: 18
Joined: Thu Aug 31, 2006 6:23 pm

Post by Rooster242 »

using:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

the locale needs to be dynamic. i'm just using 'eng' as an example.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Better set the charset in a http header.
This might already be the case and when http header and meta/charset conflict, browsers usually prefer the header or get confused.
see http://de2.php.net/manual/en/ini.core.p ... lt-charset
Post Reply