iso charset

Posted on 2011-10-17
Last Modified: 2012-05-12
how do i use this  to change the charset in php?

thanks in advance for help!
Question by:only1wizard
    LVL 3

    Expert Comment

    as my knowledge i think set charset is not related to php it's related to html.
    but if you want to set it with php you should using following code
    header('Content-type: text/html; charset=utf-8');

    Open in new window


    Author Comment

    not charset but the codec if you will look at the link provided is a list of of codecs.

    what im trying to do is set the locale

    /* Set locale to Dutch */
    setlocale(LC_ALL, 'nl_NL');
    /* Output: vrijdag 22 december 1978 */
    echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
    /* try different possible locale names for german as of PHP 4.3.0 */
    $loc_de = setlocale(LC_ALL, 'jpn');
    echo "Preferred locale for german on this system is '$loc_de'";

    Open in new window

    how ever when i use japan which is jpn i get nothing.
    LVL 3

    Expert Comment

    in my code snippet i have following code:
             * List of ISO-639-1.
             * Two letter code to Language mapping
             * If you need three letter code to Language mappng,
             * then fetch ISO-639-2
                'aa' => 'Afar',
                'ab' => 'Abkhazian',
                'af' => 'Afrikaans',
                'am' => 'Amharic',
                'ar' => 'Arabic',
                'as' => 'Assamese',
                'ay' => 'Aymara',
                'az' => 'Azerbaijani',
                'ba' => 'Bashkir',
                'be' => 'Byelorussian',
                'bg' => 'Bulgarian',
                'bh' => 'Bihari',
                'bi' => 'Bislama',
                'bn' => 'Bengali; Bangla',
                'bo' => 'Tibetan',
                'br' => 'Breton',
                'ca' => 'Catalan',
                'co' => 'Corsican',
                'cs' => 'Czech',
                'cy' => 'Welsh',
                'da' => 'Danish',
                'de' => 'German',
                'dz' => 'Bhutani',
                'el' => 'Greek',
                'en' => 'English',
                'eo' => 'Esperanto',
                'es' => 'Spanish',
                'et' => 'Estonian',
                'eu' => 'Basque',
                'fa' => 'Persian',
                'fi' => 'Finnish',
                'fj' => 'Fiji',
                'fo' => 'Faeroese',
                'fr' => 'French',
                'fy' => 'Frisian',
                'ga' => 'Irish',
                'gd' => 'Scots Gaelic',
                'gl' => 'Galician',
                'gn' => 'Guarani',
                'gu' => 'Gujarati',
                'ha' => 'Hausa',
                'hi' => 'Hindi',
                'hr' => 'Croatian',
                'hu' => 'Hungarian',
                'hy' => 'Armenian',
                'ia' => 'Interlingua',
                'ie' => 'Interlingue',
                'ik' => 'Inupiak',
                'in' => 'Indonesian',
                'is' => 'Icelandic',
                'it' => 'Italian',
                'iw' => 'Hebrew',
                'ja' => 'Japanese',
                'ji' => 'Yiddish',
                'jw' => 'Javanese',
                'ka' => 'Georgian',
                'kk' => 'Kazakh',
                'kl' => 'Greenlandic',
                'km' => 'Cambodian',
                'kn' => 'Kannada',
                'ko' => 'Korean',
                'ks' => 'Kashmiri',
                'ku' => 'Kurdish',
                'ky' => 'Kirghiz',
                'la' => 'Latin',
                'ln' => 'Lingala',
                'lo' => 'Laothian',
                'lt' => 'Lithuanian',
                'lv' => 'Latvian, Lettish',
                'mg' => 'Malagasy',
                'mi' => 'Maori',
                'mk' => 'Macedonian',
                'ml' => 'Malayalam',
                'mn' => 'Mongolian',
                'mo' => 'Moldavian',
                'mr' => 'Marathi',
                'ms' => 'Malay',
                'mt' => 'Maltese',
                'my' => 'Burmese',
                'na' => 'Nauru',
                'ne' => 'Nepali',
                'nl' => 'Dutch',
                'no' => 'Norwegian',
                'oc' => 'Occitan',
                'om' => '(Afan) Oromo',
                'or' => 'Oriya',
                'pa' => 'Punjabi',
                'pl' => 'Polish',
                'ps' => 'Pashto, Pushto',
                'pt' => 'Portuguese',
                'qu' => 'Quechua',
                'rm' => 'Rhaeto-Romance',
                'rn' => 'Kirundi',
                'ro' => 'Romanian',
                'ru' => 'Russian',
                'rw' => 'Kinyarwanda',
                'sa' => 'Sanskrit',
                'sd' => 'Sindhi',
                'sg' => 'Sangro',
                'sh' => 'Serbo-Croatian',
                'si' => 'Singhalese',
                'sk' => 'Slovak',
                'sl' => 'Slovenian',
                'sm' => 'Samoan',
                'sn' => 'Shona',
                'so' => 'Somali',
                'sq' => 'Albanian',
                'sr' => 'Serbian',
                'ss' => 'Siswati',
                'st' => 'Sesotho',
                'su' => 'Sundanese',
                'sv' => 'Swedish',
                'sw' => 'Swahili',
                'ta' => 'Tamil',
                'te' => 'Tegulu',
                'tg' => 'Tajik',
                'th' => 'Thai',
                'ti' => 'Tigrinya',
                'tk' => 'Turkmen',
                'tl' => 'Tagalog',
                'tn' => 'Setswana',
                'to' => 'Tonga',
                'tr' => 'Turkish',
                'ts' => 'Tsonga',
                'tt' => 'Tatar',
                'tw' => 'Twi',
                'uk' => 'Ukrainian',
                'ur' => 'Urdu',
                'uz' => 'Uzbek',
                'vi' => 'Vietnamese',
                'vo' => 'Volapuk',
                'wo' => 'Wolof',
                'xh' => 'Xhosa',
                'yo' => 'Yoruba',
                'zh' => 'Chinese',
                'zu' => 'Zulu');

    Open in new window

    LVL 107

    Expert Comment

    by:Ray Paseur
    LVL 16

    Expert Comment

    Ypu are doing the right thing by using the setlocale function; you need to remember that this function sets locale information including time numbers money formats collate, characters conversion  and more.
    See this link for the list of categories.

    Author Comment

    sorry for the late response just been busy.

    this is the way i want to go is with setlocale.

    do you have a link for the language section for setlocale function?

    thanks in advance for your help!

    Author Comment

    @ray can you show me an example on how to use iso 639-1 to set the language based on user language setting through geolocation region/state/ip?

    what im trying to acomplish is:

    1. grab current users language
    2. change the default websites language to use their language standards closest to their region based upon the region/state/providence/ip address provided per user.
    3. have sub domains for each region(language (primary))
    4. default language going into the database would be english but the user will input their language say japanesse and its inserts as english but displays as japaneese. im using utf-unicode-ci to ensure that the database can handle majority of languages.
    5. sorry for such a delay on this open question! thanks in advance for your help!
    LVL 33

    Expert Comment

    greetings only1wizard, you say -> "how ever when i use japan which is jpn i get nothing", if you are getting some text out put with other languages, and not Japanese, it may be that it is not the setlocale( ) function or other PHP, it may be that on your computer there are NOT mutibyte charaters for the Japanese output in your browser, or there may not be settings for Japanese placed in your operating system. I had problems in understanding the very different display considerations for mutibyte character sets that are not from the Latin-european language base. This seems to be a difficult thing to do a multi language web site, at least for me. You may consider some of the "Web Page translators" like Google translate at -

    Author Comment

    i will read into that thank u!
    LVL 107

    Accepted Solution

    example on how to use iso 639-1 to set the language based on user language setting through geolocation region/state/ip?

    There are many moving parts to that request, and integrating them will be a painstaking and laborious process.  And after you have gone to the trouble to do all of that, you will find that you have annoyed your clients by forcing (for example) the French to use the German version of the web site when their travels take them to Germany, where the automation will choose German.  But that said, ...

    How to map IP address to country

    How to do it the "nice" way and let your client choose the preferred language

    Note that in the second article, the web site uses subdirectories, not subdomains.  I suppose you could use subdomains if you wanted to.  You would need to be careful of sessions and cookies with subdomains.  This is the way works (using subdirectories).

    Note also this quote from PHP only supports a 256-character set, and hence does not offer native Unicode support.

    You can learn more about character encoding and how to use multi-byte characters in this article.

    PHP supports internationalization and multi-byte characters, sort of, via extensions

    Ultimately, this means writing correct programs using Unicode depends on carefully avoiding functions that will not work and that most likely will corrupt the data and using instead the functions that do behave correctly, generally from the intl and mbstring extensions. However, using functions that can handle Unicode encodings is just the beginning. No matter the functions the language provides, it is essential to know the Unicode specification. For instance, a program that assumes there is only uppercase and lowercase is making a wrong assumption.

    It's a big challenge to internationalize a web site.  Best of luck with it, ~Ray

    Author Comment

    @ray thank you i will read into this and post my response at a later time!
    LVL 107

    Expert Comment

    by:Ray Paseur
    Take your time and enjoy the new year - I will be here!

    Author Comment

    thank you u2

    Author Closing Comment

    thanks for your help with internationalize a website!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now