0

how can i detect and convert below strings to readable string this strings?

  1. سئوالات
  2. مطاعن ابوبكر
  3. مطاعن عمر

since these strings with UTF-8 in MySQL database and our language is Arabic and Persian they are unreadable for us and I'm not sure how can we convert them to normal readable strings

sql table structure:

CREATE TABLE `categories` (
  ...
  `title` longtext,
  `tblname` longtext,
  ...
  PRIMARY KEY (`number`)
) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8;

is there any online service or solution to convert them to readable strings before using them and importing into database?

we don't want to convert them inside php code with iconv or convert inside sql, we want to only convert them to have simple sql code before inserting into the database

DolDurma
  • 15,753
  • 51
  • 198
  • 377
  • How is PHP related? Do you set the charset on your db connection? – user3783243 Jan 31 '21 at 04:54
  • @this structure should be used with php, and we want to what are they in the first time before using them. they are unreadable in database too – DolDurma Jan 31 '21 at 04:56
  • 1
    How did you end up with `س` in DB? Please add script and DB connection code. What should that be? It likely is lost because connection was set incorrectly. – user3783243 Jan 31 '21 at 05:00
  • @user3783243 this `sql` exported with `Navicat MySQL Data Transfer`, your mean is setting `charset` db connection was incorrect with that? – DolDurma Jan 31 '21 at 05:02
  • @DolDurma, Have you tried using `iconv` to convert between character sets? – Mark Jan 31 '21 at 07:56
  • 1
    You have a case of [mojibake](https://en.wikipedia.org/wiki/Mojibake) because you’ve mistreated encodings somewhere. Is it necessary to somehow fix this afterwards now, or can you simply fix your flow to treat encodings correctly along the way to avoid this problem altogether? – deceze Jan 31 '21 at 07:58
  • @deceze this `sql` is not our and we should fix `utf-8` before importing into the `mysql` database. we don't know how can we convert it – DolDurma Jan 31 '21 at 08:11

2 Answers2

0

You should use mysqli_set_charset() function before uploading/updating any string in database.

$conn = new mysqli(host,user,pass,dbname);

if($conn->connect_error){
    die("Connection failed: ".$conn->connect_error);
    exit();
}

mysqli_set_charset($conn,"utf8mb4");


// your query here
-1

this online service resolve our problem, which with that we can convert Unicode to correct readable characters

online service link

DolDurma
  • 15,753
  • 51
  • 198
  • 377