Hello everybody,
I have this text file, and when I import them into mysql through phpMyAdmin, everything is ok, but the persian (Farsi) not shown correctly, also I use ' utf8_persian_ci ' collation, can anyone kindly plz convert this file into MySQL that farsi data shows correctly too?

NOTE:
farsi "persian" is a language

Dani AI

Generated

As observed, the symptoms (file looks fine in a Windows viewer when you pick "Arabic (Windows)" but becomes garbled after import) strongly point to an encoding mismatch: the .txt is encoded in a Windows Arabic code page (e.g., CP1256) while the import/DB connection expects Unicode. That difference in raw bytes is the real problem — changing column collation alone won't repair already‑wrong bytes.

Practical fix (short workflow):

  1. Detect the .txt encoding (Notepad++ Encoding menu, file -i/enca on Linux, or use PHP’s mb_detect_encoding).
  2. Convert the file to UTF‑8 without a BOM (recommended) or keep it as CP1256 but tell the importer which charset to use. Example conversion with iconv:
iconv -f CP1256 -t UTF-8 input.txt > input-utf8.txt
  1. Import using the matching file charset (phpMyAdmin has a "character set of the file" option; LOAD DATA INFILE supports CHARACTER SET), and make sure your PHP/MySQL connection is set to the same charset before INSERT/SELECT. For mysqli:
$mysqli = new mysqli(...);
$mysqli->set_charset('utf8mb4');

Quick troubleshooting tips:

  • If manual INSERT works but import does not, inspect the stored bytes with SELECT HEX(your_column). UTF‑8 Persian should show multi‑byte hex sequences; if you see CP1256 byte values the bytes are wrong for UTF‑8 rendering.
  • Remove any UTF BOM (it can confuse imports).
  • Use utf8mb4 for modern MySQL setups to avoid surprises with extended Unicode.

Reference reading: PHP’s mysqli::set_charset and iconv docs and MySQL character set guidance can help with the exact commands and options (mysqli_set_charset, iconv, MySQL charset docs).

Recommended Answers

All 10 Replies

what was wrong with the persian text?

Persian text not shwon at all when I use the utf8_persian_ci...and if I change the collation then persian text shown like attachment

i made a test script to see if it worked with my database. it worked just fine, the text looked a little different but its still the same. have you echoed the info to a page to see if its the same? look here.

yeah it is ok, if I select the encoding of the window " Arabic (Windows) ", otherwise it is not readable.

if I manually insert the data into MySQL database, then persian text is OK...

any suggestion plz...

I'ld like to draw your attention that it's also related to the hosting server that you're hosting the site on it, cause most of those servers their mysql default character set is MySQL charset: UTF-8 Unicode (utf8) so it's recommended to ask the host server company to change it for you to your charecter set code.

I am using on my own computer not on the server, just i have installed appachi on my pc, also when I create the db I change the collation to "utf8_persian-ci" but the persian word is not imported, the english words are ok...

it's not enaugh to change the collation of the database you have to change the collation for the needed table and the needed field also.
when you chose the database chose the table and click operations and change the collation in the same way chose the table and the needed field and click operations to change the field collation it will show right charecter set

Thnx much all...

Hello,
I am using Windows local PHP, MySQLO and Apache.

I have the same issue. I have Persian Text on .txt file, when double click and open it, it shows fine but when I insert it into Database , it is unreadable.

I used PHP to just read and display it on the screen, and use:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
on the page, it just shows questions marks ????????????????? instad of the text.
I opened the source of the page in Internet Explorer and it shows the same ??????????????????????????? instead of the.

use this

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and also use 
<body lang="far" dir="rtl">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.