1

I have a website connected to the database and I used arabic words to save it in the database. It works fine when I insert the words manually in phpmyadmin but when I try to insert it using php it doesn't work and it is displayed like this in the database: & # 1 5 9 3 ; & # 1 6 0 4 ; & # 1 6 1 0;

I also added this code after connecting to the database but still didn't work:

mysql_select_db('databasename',$con);

mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");  
Abatef
  • 13
  • 2
  • I realized something, when I added this (& # 1 5 9 3 ; & # 1 6 0 4 ; & # ) in the question it becomes arabic, I don't know why? thats why I had to separate it. – Abatef Mar 30 '15 at 13:13
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo). – Jay Blanchard Mar 30 '15 at 13:13

1 Answers1

0

You are inserting HMTL entities. Need to convert them to the actual Arabic text. Use html_entity_decode() on the strings to be inserted.

Markus AO
  • 4,771
  • 2
  • 18
  • 29
  • Glad to oblige. P.S. If you work with Arabic and need to normalize stuff into ASCII transliteration (e.g. for URLs), you may also find the PHP transliterator useful. E.g. `echo transliterator_transliterate('Arabic-Latin', 'بسم الله الرحمن الرحيم');` Not entirely satisfied with it though, so I've been chipping away at a custom transliteration setup that is both readable (as in, pronounceable) and lossless (can convert back to Arabic script). Msg me if you need raw prototype codes. – Markus AO Mar 30 '15 at 14:37