1--TEST-- 2Test setlocale() function : basic functionality - passing multiple locales as argument 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip Not valid for windows'); 7} 8if (setlocale(LC_ALL, "en_US.utf8", "Ko_KR.utf8", "zh_CN.utf8") === false) { 9 die('skip en_US.utf8/Ko_KR.utf8/zh_CN.utf8 locales not available'); 10} 11?> 12--FILE-- 13<?php 14/* Prototype : string setlocale (int $category , string $locale [,string $..] ) 15 : string setlocale(int $category , array $locale); 16 * Description: Sets locale information.Returns the new current locale , or FALSE 17 if locale functionality is not implemented in this platform. 18 * Source code: ext/standard/string.c 19*/ 20 21/* Test the setlocale() when multiple locales are provided as argument */ 22 23/* Prototype : array list_system_locales( void ) 24 Description: To get the currently installed locle in this platform 25 Arguments : Nil 26 Returns : set of locale as array 27*/ 28function list_system_locales() { 29 // start the buffering of next command to internal output buffer 30 ob_start(); 31 32 // run the command 'locale -a' to fetch all locales available in the system 33 system('locale -a'); 34 35 // get the contents from the internal output buffer 36 $all_locales = ob_get_contents(); 37 38 // fflush and end the output buffering to internal output buffer 39 ob_end_clean(); 40 41 $system_locales = explode("\n", $all_locales); 42 43 // return all the locale found in the system 44 return $system_locales; 45} 46 47/* Collect existing system locales and get three locales that can be use to 48 pass as argument to setlocale() */ 49echo "*** Testing setlocale() by passing multiple locales as argument ***\n"; 50 51 52//set of currency symbol according to above list of locales 53$currency_symbol = array( 54 "en_US.utf8" => "USD", 55 "en_AU.utf8" => "AUD", 56 "ko_KR.utf8" => "KRW", 57 "zh_CN.utf8" => "CNY", 58 "de_DE.utf8" => "EUR", 59 "es_EC.utf8" => "USD", 60 "fr_FR.utf8" => "EUR", 61 "ja_JP.utf8" => "JPY", 62 "el_GR.utf8" => "EUR", 63 "nl_NL.utf8" =>"EUR" 64); 65 66// gather all the locales installed in the system 67$all_system_locales = list_system_locales(); 68 69// Now check for three locales that is present in the system and use that as argument to setlocale() 70if( in_array("en_US.utf8",$all_system_locales) || 71 in_array("Ko_KR.utf8",$all_system_locales) || 72 in_array("zh_CN.utf8",$all_system_locales) ) { 73 echo "-- Testing setlocale() by giving 'category' as LC_ALL & multiple locales(en_US.utf8, Ko_KR.utf8, zh_CN.utf8) --\n"; 74 75 // call setlocale() 76 $new_locale = setlocale(LC_ALL, "en_US.utf8", "Ko_KR.utf8", "zh_CN.utf8"); 77 78 // dump the name of the new locale set by setlocale() 79 var_dump($new_locale); 80 81 // check that new locale setting is effective 82 // use localeconv() to get the details of currently set locale 83 $locale_info = localeconv(); 84 $new_currency = trim($locale_info['int_curr_symbol']); 85 86 echo "Checking currency settings in the new locale, expected: ".$currency_symbol[$new_locale].", Found: ".$new_currency."\n"; 87 echo "Test "; 88 if( trim($currency_symbol[$new_locale]) == $new_currency) { 89 echo "PASSED.\n"; 90 } else { 91 echo "FAILED.\n"; 92 } 93} 94 95echo "Done\n"; 96?> 97--EXPECTF-- 98*** Testing setlocale() by passing multiple locales as argument *** 99-- Testing setlocale() by giving 'category' as LC_ALL & multiple locales(en_US.utf8, Ko_KR.utf8, zh_CN.utf8) -- 100string(%d) "%s" 101Checking currency settings in the new locale, expected: %s, Found: %s 102Test PASSED. 103Done 104