Expert Refresh

Formatting

1) Which function returns the ASCII value 65?




2) Which function returns A?




3) If "333" string is given, how do you obtain the string "000333"?







ord() - Return ASCII value of character <?php echo ord("A"); // 65 chr() - Return character by ASCII code <?php echo chr(65); // A number_format() - is not locale-aware <?php echo number_format("100000.698"); // 100,001 // returns a rounded number echo number_format("100000.698", 3, ",", " "); // 100 000,698 str_pad() - Pad a string to a certain length with another string <?php echo str_pad("100", 6, "0"); // Output: 100000 echo str_pad("333", 6, "0", STR_PAD_LEFT); // Output: 000333 money_format() <?php // is locale-aware // not available on Windows, as well as on some variants of UNIX setlocale(LC_MONETARY, "en_US"); echo money_format('%.2n', "100000.698"); // $100,000.70 setlocale(LC_MONETARY, "ro_RO"); echo money_format('%.2n', "100000.698"); // Lei 100.000,70 If we change our formatting to use the i conversion character, money_format() will produce its output using the international notation. <?php setlocale(LC_MONETARY, "en_US"); echo money_format('%.2i', "100000.698"); // USD 100,000.70 In addition, you should keep in mind that the default rounding rules change from locale to locale. For example, US currency values are regularly expressed as dollars and cents, while Japanese currency values are represented as integers. <?php setlocale(LC_MONETARY, "en_US"); echo money_format('%i', "100000.698"); // USD 100,000.70 setlocale(LC_MONETARY, "ja_JA"); echo money_format('%i', "100000.698"); // JPY 100,001


References