From 56a0ec9638a1bb212ee05a114f5debf8c62c8b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 21 Feb 2006 20:28:27 +0000 Subject: [PATCH] Skip byte order marks (bug #1423362). --- ChangeLog | 1 + libraries/import.lib.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index d68259139..a80175a1e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,7 @@ $Source$ * libraries/iconv_wrapper.lib.php, libraries/charset_conversion.lib.php, libraries/database_interface.lib.php: Compatibility with iconv charset names on AIX (patch #1420704, thanks to Björn Wiberg - bwiberg). + * libraries/import.lib.php: Skip byte order marks (bug #1423362). 2006-02-21 Sebastian Mendel * libraries/common.lib.php PMA_getUvaCondition(): diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 0562575d5..a99606aa0 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -251,6 +251,19 @@ function PMA_importGetNextChunk($size = 32768) if ($charset_conversion) { return PMA_convert_string($charset_of_file, $charset, $result); } else { + // Skip possible byte order marks (I do not think we need more + // charsets, but feel free to add more, you can use wikipedia for + // reference: ) + // @TODO: BOM could be used for charset autodetection + if ($offset == $size) { + // UTF-8 + if (strncmp($result, "\xEF\xBB\xBF", 3) == 0) { + $result = substr($result, 3); + // UTF-16 BE, LE + } elseif (strncmp($result, "\xFE\xFF", 2) == 0 || strncmp($result, "\xFF\xFE", 2) == 0) { + $result = substr($result, 2); + } + } return $result; } }