<?php
declare(encoding="latin1");
$a = "1234å67890";
file_put_contents( "/tmp/testuc.1", $a);
file_put_contents( "/tmp/testuc.2", (string) $a);
$context = stream_context_create();
stream_context_set_params($context, array( "output_encoding" => "latin1" ) );
file_put_contents( "/tmp/testuc.3", $a, FILE_TEXT, $context);
file_put_contents( "/tmp/testuc.4", (string) $a, FILE_TEXT, $context);
?>
But it still throws a warning on ".3". It's a small design issue that I
didn't want to touch right now.
if (numchars < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write %d characters to %s", ustrlen, filename);
numchars = -1;
- } else if (numchars != UBYTES(Z_USTRLEN_P(data))) {
+ } else if (numchars != ustrlen) {
int numchars = u_countChar32(Z_USTRVAL_P(data), numchars);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d characters written, possibly out of free disk space", numchars, ustrlen);
stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC);
}
- if (stream->output_encoding) {
+ if (stream->output_encoding && buf_type == IS_UNICODE) {
char *dest;
int destlen;
UErrorCode status = U_ZERO_ERROR;
buflen = destlen;
} else {
/* Sloppy handling, make it a binary buffer */
- buflen = UBYTES(buflen);
+ if (buf_type != IS_STRING) {
+ buflen = UBYTES(buflen);
+ }
}
while (buflen > 0) {