#19154 [Csd]: Include "encoding" argument in utf8_encode function

From: Date: Thu, 29 Aug 2002 14:07:26 +0000
Subject: #19154 [Csd]: Include "encoding" argument in utf8_encode function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18151@lists.php.net to get a copy of this message
ID: 19154 Updated by: wez@php.net Reported By: dimitris@ccf.auth.gr Status: Closed Bug Type: Feature/Change Request PHP Version: 4.2.2 New Comment: Not at all; the utf8_encode functions work as documented; anyone using those functions has accepted that functionality. People that need more flexibility will be using the mbstring functions instead. mbstring is enabled by default as of PHP 4.3, so it does not make sense to duplicate code and functionality in the way you have described between the various modules as it makes things harder to maintain, and potentially more error prone. Previous Comments: ------------------------------------------------------------------------ [2002-08-29 03:44:52] dimitris@ccf.auth.gr Indeed, the mbstring extension seems to target multi-byte languages and conversion. But the default PHP functions for handling UTF-8 are tf8_encode/utf8_decode. Forcing those functions to support only ISO-8859-1 is obviously temporary, until mb_string is integrated into the main PHP package, and all related functions utilize it. However, this temporary choice restricts many already developed PHP packages that use the utf8 functions (e.g. HORDE/IMP) to just the ISO-8859-1 encoding. IMHO, this is wrong. ------------------------------------------------------------------------ [2002-08-28 12:47:15] wez@php.net Try using mb_convert_encoding in the mbstring extension. ------------------------------------------------------------------------ [2002-08-28 11:38:05] dimitris@ccf.auth.gr We wanted a way to convert to utf8 strings originating from other than ISO-8859-1 encodings. Looking through the source code in PHP_SOURCE/ext/xml/xml.c we found out that the utf8_encode function has hardwired the ISO-8859-1 encoding method in it, even though the xml_utf8_encode function has already provisions for choosing another encoding (if implemented). See PHP_FUNCTION(utf8_encode): encoded = xml_utf8_encode(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &len, "ISO-8859-1"); And see: static XML_Char *xml_utf8_encode(const char *s, int len, int *newlen, const XML_ Char *encoding) If PHP is interested in providing UTF-8 conversion support for other lanaguages (encodings), then this extra argument is necessary for the user to be able to indicate originating encoding for the text he is about to convert. As for utf8_decode, that function does not need an indication of target encoding since the originating text in Unicode already specifies language. I have patched xml.c for ISO-8859-7 and I would be more than willing to cooperate with anybody who takes this up, share code and knowledge. I have also posted my "fixes" in the manual page for utf8_encode. Thanks. Dimitris Daskopoulos NOC, Aristotle University of Thessaloniki ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=19154&edit=1

« previous php.bugs (#18151) next »