Proposed addition to PHP4 - "htmlentities_utf8()"

From: Date: Sun, 03 Dec 2000 19:18:40 +0000
Subject: Proposed addition to PHP4 - "htmlentities_utf8()"
Groups: php.i18n 
Request: Send a blank email to php-i18n+get-84@lists.php.net to get a copy of this message
Dear Sirs, I'm subscribing to this list for the sole purpose of submitting these files. Please redirect all answers to the e-mail address listed above (answers are really not expected, hence this paragraph), as this I will un-subscribe just after sending these. I found no better place where to submit this. I apologise if this is not the proper location - please forward the message elsewhere is not. Thank you very much, Pedro Freire PROPOSED ADDITION TO PHP4 ------------------------- Files html.h html.c basic_functions.c are attached, and should be placed on folder /ext/standard of the PHP 4.0.3pl1 source distribution. They create a new PHP4 function htmlentities_utf8() that works *exactly* like htmlentities(), except that it assumes the underlying charset is UTF-8 instead of ISO-Latin-1. Its workings are very simple: HTML 4 specifies that numeric character entities in the form &#dddd; define the numeric code for a *Unicode* (actually ISO-10646) char. htmlentities_utf8() just decodes long UTF-8 sequences into their Unicode code, and encodes them as shown above. Note that the full 31-bit ISO-10646 charset is supported by UTF-8 and htmlentities_utf8(), not only 16-bit Unicode. This encoding is backwards compatible to at least HTML 2, even though old browsers will probabily not like the code anyway as HTML prior to version 4 specified the default encoding as ISO-Latin-1 and made no reference to the underlying charset of &#ddd; entities. But it also did not define a maximum number of decimal digits allowed in such entities, which makes those previous standards compatible with HTML 4 (though probabily not the implementations). UTF-8 is an encoding for ISO-10646, of which Unicode itself is a subset (the so-called "Basic Multilingual Plane", or BMP). Until today, there are no character encodings in ISO-10646 that are not in Unicode, and it is expected that only a few "esoteric" characters will ever be outside of Unicode (as hieroglyphs). The code as submitted will ignore invalid UTF-8 encodings (they will be silently "eaten away"), with the exception of 0xFE and 0xFF which will be output without change. **NOTE** This code has *NOT* been tested - it hasn't even been compiled! It was written in a few minutes as I assumed it should be simple enough to add to PHP4, and I seem to be right. We at CYNERGI are going to launch IV-Generation hosting services in early/middle of 2001, and if by then PHP4 has not included this function as a standard, we will be making it a proprietary addition (assuming the licence allows it - I must admit I haven't read it yet). This is essencial to providing localized services. To find the changes to the original files, search for the character sequence "!!!" (3 exclamation marks). Enjoy the code. Date: 3rd December 2000 Author: Pedro Freire Company: CYNERGI E-mail: pedro.freire@cynergi.net Personal URL: www.pedrofreire.com Company URL: www.cynergi.net

Attachment: [application/x-zip-compressed] PHP v4.0.3pl1 src +utf8.zip
« previous php.i18n (#84) next »