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:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user