From: Hartmut Holzgraefe Date: Fri, 2 Aug 2002 10:08:53 +0000 (+0000) Subject: added money_format() function X-Git-Tag: dev~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5fa36eee4da397645498de55d957c4a438026e1;p=php added money_format() function this is similar to C-libs strfmon(), using the same format string semantics but a different function prototype, so i decided to give it a more speaking name similar to number_format() --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index ebafd20e30..24df4bf049 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -321,6 +321,10 @@ function_entry basic_functions[] = { PHP_FE(strcoll, NULL) #endif +#ifdef HAVE_STRFMON + PHP_FE(money_format, NULL) +#endif + PHP_FE(substr, NULL) PHP_FE(substr_replace, NULL) PHP_FE(quotemeta, NULL) diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index 89ddabeda1..8fc91f6bc2 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -227,6 +227,8 @@ AC_ARG_WITH(regex, AC_CHECK_FUNCS(fnmatch glob) +AC_CHECK_FUNCS(strfmon) + if test "$PHP_SAPI" = "cgi"; then AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function]) fi diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index eb6330c34b..d63f91b254 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -85,7 +85,9 @@ PHP_FUNCTION(sscanf); #ifdef HAVE_STRCOLL PHP_FUNCTION(strcoll); #endif - +#if HAVE_STRFMON +PHP_FUNCTION(money_format); +#endif #if defined(HAVE_LOCALECONV) && defined(ZTS) PHP_MINIT_FUNCTION(localeconv); diff --git a/ext/standard/string.c b/ext/standard/string.c index 499eed7ee4..0940eab539 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -3904,6 +3904,28 @@ PHP_FUNCTION(str_rot13) /* }}} */ +#if HAVE_STRFMON +/* {{{ proto string money_format(string format , float value) + Convert monetary value(s) to string */ + +PHP_FUNCTION(money_format) { + int format_len, str_len = 1024; + char *format, *str = emalloc(str_len); + double value; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", + &format, &format_len, &value) == FAILURE) { + return; + } + + str_len = strfmon(str, str_len, format, value); + + RETURN_STRINGL(erealloc(str, strlen), str_len, 0); +} + +/* }}} */ +#endif + /* * Local variables: * tab-width: 4