From 77b4d4be499d2ad1dd7a838602dc4f4a6093aaae Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 10 Apr 2007 15:32:37 +0000 Subject: [PATCH] MDL-9075 utf-8 bom is now stripped from uploaded users cvs file; merged from MOODLE_18_STABLE --- admin/uploaduser.php | 5 ++++- lib/textlib.class.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/admin/uploaduser.php b/admin/uploaduser.php index 5a5ecfe6c6..a13ebe74d4 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -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); diff --git a/lib/textlib.class.php b/lib/textlib.class.php index b8a570c619..dd2626f81e 100644 --- a/lib/textlib.class.php +++ b/lib/textlib.class.php @@ -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; + } } ?> -- 2.39.5