Storing utf8 `рдореЗрд░рд╛ рднрд╛рд░рдд рдорд╣рд╛рди` data in a database

I want to store UTF8 in a database. I have data in Unicode Hindi, and I want to store it in a MySQL database using php, after converting it to HTML character sets. Let someone enter a bullet character (тАв) in the text box. When saving this data, you should convert it to • .

Suppose I have data рдореЗрд░рд╛ рднрд╛рд░рдд рдорд╣рд╛рди I want to save it in a database by translating it into an html character. How can i do this? I tried using the htmlentities function, but this does not work satisfactorily for me.

+4
source share
2 answers

Objects • are called HTML entities. PHP has a function that can create them: mb_encode_numericentity Docs , this is part of the Multibyte String Extension ( Demo ):

 $string = 'рдореЗрд░рд╛ рднрд╛рд░рдд рдорд╣рд╛рди'; $encoding = 'UTF-8'; $convmap = array(0, 0xffff, 0, 0xffff); $encoded = mb_encode_numericentity($string, $convmap, $encoding); echo $encoded; मेरा भारत महान 

However: you need to know the encoding of your string. In this case, I chose UTF-8 , depending on this you need to change the $encoding parameter of the function and the $convmap .

However, do not store it this way in your database. Keep it as it is and convert the output encoding after , you have extracted data from your database. / P>

Similar question: Convert (doublebyte) string to hexadecimal

+3
source

htmlentities has the charset parameter, Try: htmlentities($text, ENT_COMPAT, "UTF-8")

0
source

Source: https://habr.com/ru/post/1383028/


All Articles