While we're in there, let's remove a dependency on iconv(). Do the UTF-16 to ASCII...
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 5 Feb 2008 23:13:17 +0000 (23:13 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 5 Feb 2008 23:13:17 +0000 (23:13 +0000)
includes/MimeMagic.php

index 8ba9925..77a3062 100644 (file)
@@ -479,9 +479,17 @@ class MimeMagic {
                        */
                }
 
-               if ( $xml_type ) {
-                       if ( $xml_type !== "UTF-8" && $xml_type !== "ASCII" ) {
-                               $head = iconv( $xml_type, "ASCII//IGNORE", $head );
+               if( $xml_type == 'UTF-16BE' || $xml_type == 'UTF-16LE' ) {
+                       // Quick and dirty fold down to ASCII!
+                       $pack = array( 'UTF-16BE' => 'n*', 'UTF-16LE' => 'v*' );
+                       $chars = unpack( $pack[$xml_type], substr( $head, 2 ) );
+                       $head = '';
+                       foreach( $chars as $codepoint ) {
+                               if( $codepoint < 128 ) {
+                                       $head .= chr( $codepoint );
+                               } else {
+                                       $head .= '?';
+                               }
                        }
                }