summaryrefslogtreecommitdiff
path: root/inc/utf8.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2005-10-17 22:04:31 +0200
committerAndreas Gohr <andi@splitbrain.org>2005-10-17 22:04:31 +0200
commit15fa0b4f1d7eb4b260ff5b8025c56fce3681148e (patch)
treeeb71f504982f49e497ada40bbbac35b24383a72a /inc/utf8.php
parentfaa28b7fc56238d32739d949fd2df3bffe33b1ba (diff)
downloadrpg-15fa0b4f1d7eb4b260ff5b8025c56fce3681148e.tar.gz
rpg-15fa0b4f1d7eb4b260ff5b8025c56fce3681148e.tar.bz2
removed mb_string requirement in JSON.php #592
darcs-hash:20051017200431-7ad00-c9ed74326a44b078cc516e08515375d9d0fba811.gz
Diffstat (limited to 'inc/utf8.php')
-rw-r--r--inc/utf8.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/inc/utf8.php b/inc/utf8.php
index 79baf2df7..7e82e7cd2 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -377,7 +377,7 @@ function utf8_tohtml ($str) {
* @link http://www.randomchaos.com/document.php?source=php_and_unicode
* @see unicode_to_utf8()
*/
-function utf8_to_unicode( $str ) {
+function utf8_to_unicode( &$str ) {
$unicode = array();
$values = array();
$lookingFor = 1;
@@ -408,7 +408,7 @@ function utf8_to_unicode( $str ) {
* @link http://www.randomchaos.com/document.php?source=php_and_unicode
* @see utf8_to_unicode()
*/
-function unicode_to_utf8( $str ) {
+function unicode_to_utf8( &$str ) {
$utf8 = '';
foreach( $str as $unicode ) {
if ( $unicode < 128 ) {
@@ -426,6 +426,33 @@ function unicode_to_utf8( $str ) {
}
/**
+ * UTF-8 to UTF-16BE conversion.
+ *
+ * Maybe really UCS-2 without mb_string due to utf8_to_unicode limits
+ */
+function utf8_to_utf16be(&$str, $bom = false) {
+ $out = $bom ? "\xFE\xFF" : '';
+ if(!defined('UTF8_NOMBSTRING') && function_exists('mb_convert_encoding'))
+ return $out.mb_convert_encoding($str,'UTF-16BE','UTF-8');
+
+ $uni = utf8_to_unicode($str);
+ foreach($uni as $cp){
+ $out .= pack('n',$cp);
+ }
+ return $out;
+}
+
+/**
+ * UTF-8 to UTF-16BE conversion.
+ *
+ * Maybe really UCS-2 without mb_string due to utf8_to_unicode limits
+ */
+function utf16be_to_utf8(&$str) {
+ $uni = unpack('n*',$str);
+ return unicode_to_utf8($uni);
+}
+
+/**
* UTF-8 Case lookup table
*
* This lookuptable defines the upper case letters to their correspponding