Add convenience function stream_defualt_encoding() for setting it.
STD_ZEND_INI_ENTRY("unicode.script_encoding", NULL, ZEND_INI_ALL, OnUpdateEncoding, script_encoding_conv, zend_unicode_globals, unicode_globals)
STD_ZEND_INI_ENTRY("unicode.http_input_encoding", NULL, ZEND_INI_ALL, OnUpdateEncoding, http_input_encoding_conv, zend_unicode_globals, unicode_globals)
STD_ZEND_INI_ENTRY("unicode.filesystem_encoding", NULL, ZEND_INI_ALL, OnUpdateEncoding, filesystem_encoding_conv, zend_unicode_globals, unicode_globals)
+ STD_ZEND_INI_ENTRY("unicode.stream_encoding", "utf8", ZEND_INI_ALL, OnUpdateStringUnempty, stream_encoding, zend_unicode_globals, unicode_globals)
ZEND_INI_END()
UConverter *utf8_conv; /* all-purpose UTF-8 converter */
UConverter *ascii_conv; /* all-purpose ASCII converter */
+ char *stream_encoding; /* default stream encoding (contents, not FS entries)
+ Uses name of encoding rather than a real converter
+ because each stream needs its own instance */
+
uint16_t from_error_mode;
UChar from_subst_char[3];
uint16_t to_error_mode;
}
/* }}} */
+
+/* {{{ proto bool stream_default_encoding(string encoding) U
+Convenience wrapper for ini_set('unicode.stream_encoding', $encoding) */
+PHP_FUNCTION(stream_default_encoding)
+{
+ char *encoding;
+ int encoding_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoding, &encoding_len) == FAILURE) {
+ return;
+ }
+
+ RETURN_BOOL(SUCCESS == zend_alter_ini_entry("unicode.stream_encoding", sizeof("unicode.stream_encoding"),
+ encoding, encoding_len, PHP_INI_ALL, PHP_INI_STAGE_RUNTIME));
+}
+/* }}} */
+
+
/* {{{ proto void stream_encoding(resource stream[, string encoding])
Set character set for stream encoding
UTODO: Return current encoding charset
/* Only apply implicit unicode.to. filter if the wrapper didn't do it for us */
if ((php_stream_filter_product(&stream->writefilters, IS_UNICODE) == IS_UNICODE) &&
(strchr(implicit_mode, 'w') || strchr(implicit_mode, 'a') || strchr(implicit_mode, '+'))) {
- char *encoding = (context && context->output_encoding) ? context->output_encoding : "utf8";
+ char *encoding = (context && context->output_encoding) ? context->output_encoding : UG(stream_encoding);
/* UTODO: (Maybe?) Allow overriding the default error handlers on a per-stream basis via context params */
php_stream_encoding_apply(stream, 1, encoding, UG(from_error_mode), UG(from_subst_char));
/* Only apply implicit unicode.from. filter if the wrapper didn't do it for us */
if ((stream->readbuf_type == IS_STRING) && (strchr(implicit_mode, 'r') || strchr(implicit_mode, '+'))) {
- char *encoding = (context && context->input_encoding) ? context->input_encoding : "utf8";
+ char *encoding = (context && context->input_encoding) ? context->input_encoding : UG(stream_encoding);
/* UTODO: (Maybe?) Allow overriding the default error handlers on a per-stream basis via context params */
php_stream_encoding_apply(stream, 0, encoding, UG(to_error_mode), NULL);