البرمجة

تحويل ترميز ملف UTF-16 إلى UTF-8

Based on the screenshots you provided, it looks like the file is encoded in UTF-16 Little Endian (LE). This is why you see the characters spaced out in the MySQL table import, as UTF-16 uses two bytes per character.

To import this file into a UTF-8 MySQL table, you’ll need to convert the file to UTF-8 first. You can do this using a text editor that supports encoding conversion, or by using a command-line tool like iconv.

Here’s a general approach using iconv:

  1. Convert the file to UTF-8:

    bash
    iconv -f UTF-16LE -t UTF-8 inputfile.txt > outputfile.txt

    Replace inputfile.txt with the name of your downloaded file and outputfile.txt with the name you want for the converted file.

  2. Import the converted file into MySQL:
    Once you have the file in UTF-8 encoding, you can import it into your MySQL table using the LOAD DATA INFILE statement. Make sure your MySQL table is set to use UTF-8 encoding.

    sql
    LOAD DATA INFILE 'path_to_your_file/outputfile.txt' INTO TABLE your_table_name CHARACTER SET UTF8 FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (column1, column2, ...);

    Adjust the CHARACTER SET, FIELDS TERMINATED BY, LINES TERMINATED BY, and the list of columns (column1, column2, ...) according to your file format and table structure.

This should allow you to safely import the UTF-16 file into your UTF-8 MySQL table without the spacing issue.

المزيد من المعلومات

الملف الذي تعمل عليه مشفر بترميز UTF-16 Little Endian، وهذا ما يفسر الفراغات بين الحروف عند استيراده إلى جدول MySQL الذي يستخدم ترميز UTF-8. يجب عليك تحويل الترميز إلى UTF-8 قبل استيراده إلى جدول MySQL.

يمكنك استخدام أدوات التحويل المتاحة لتحويل ترميز الملف. على سبيل المثال، يمكنك استخدام أداة iconv في نظام التشغيل Linux لتحويل الترميز. الأمر التالي يوضح كيفية استخدام iconv لتحويل الملف إلى UTF-8:

bash
iconv -f UTF-16LE -t UTF-8 inputfile.txt > outputfile.txt

يجب استبدال inputfile.txt باسم الملف الذي قمت بتنزيله و outputfile.txt باسم الذي تريده للملف المحول.

بعد تحويل الترميز، يمكنك استيراد الملف المحول إلى جدول MySQL الخاص بك باستخدام الأمر LOAD DATA INFILE بالطريقة التي تم ذكرها في الرد السابق.

مقالات ذات صلة

زر الذهاب إلى الأعلى
إغلاق

أنت تستخدم إضافة Adblock

يرجى تعطيل مانع الإعلانات حيث أن موقعنا غير مزعج ولا بأس من عرض الأعلانات لك فهي تعتبر كمصدر دخل لنا و دعم مقدم منك لنا لنستمر في تقديم المحتوى المناسب و المفيد لك فلا تبخل بدعمنا عزيزي الزائر