MDL-72035 csvlib: Write BOM for Excel

Add option to class csv_export_writer to prefix CSV file with UTF-8 byte
order mark (BOM).  This helps Microsoft Excel detect the file's character
encoding.
This commit is contained in:
Leon Stringer
2021-06-30 14:59:15 +01:00
parent 017dce9cc3
commit 0eb14ac1d4
3 changed files with 15 additions and 3 deletions
+3 -1
View File
@@ -47,6 +47,8 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_text {
/** @var string Byte order mark for UTF-8 */
const UTF8_BOM = "\xef\xbb\xbf";
/**
* @var string[] Array of strings representing Unicode non-characters
@@ -626,7 +628,7 @@ class core_text {
* @return string
*/
public static function trim_utf8_bom($str) {
$bom = "\xef\xbb\xbf";
$bom = self::UTF8_BOM;
if (strpos($str, $bom) === 0) {
return substr($str, strlen($bom));
}