MDL-9075 utf-8 bom is now stripped from uploaded users cvs file; merged from MOODLE_1...
authorskodak <skodak>
Tue, 10 Apr 2007 15:32:37 +0000 (15:32 +0000)
committerskodak <skodak>
Tue, 10 Apr 2007 15:32:37 +0000 (15:32 +0000)
admin/uploaduser.php
lib/textlib.class.php

index 5a5ecfe6c676d7e1e7adff2d1b00468a13281a2a..a13ebe74d4faae5d904905e19dd28d0e5bd74552 100755 (executable)
@@ -67,8 +67,11 @@ if ($um->preprocess_files() && confirm_sesskey()) {
         @apache_child_terminate();
     }
 
-    //Fix mac/dos newlines
     $text = my_file_get_contents($filename);
+    //trim utf-8 bom
+    $textlib = new textlib();
+    $text = $textlib->trim_utf8_bom($text);
+    //Fix mac/dos newlines
     $text = preg_replace('!\r\n?!',"\n",$text);
     $fp = fopen($filename, "w");
     fwrite($fp,$text);
index b8a570c619d19a0602002b44f78f151885dc9314..dd2626f81ee0e706ba620b8bc76d34cede09c971 100644 (file)
@@ -322,5 +322,15 @@ class textlib {
         return $result;
     }
 
+    /**
+     * Removes the BOM from unicode string - see http://unicode.org/faq/utf_bom.html
+     */
+    function trim_utf8_bom($str) {
+        $bom = "\xef\xbb\xbf";
+        if (strpos($str, $bom) === 0) {
+            return substr($str, strlen($bom));
+        }
+        return $str;
+    }
 }
 ?>