2

Why insert in database value date as: شهريور ?

How can search this word in database(شهريور)?

 In database: structure => date => varchar(255) => utf8_general_ci = "شهريور".
hakre
  • 184,866
  • 48
  • 414
  • 792
Kate Thompson
  • 433
  • 2
  • 5
  • 13

2 Answers2

2

You website uses an encoding in which these characters do not exists, so the browser sends HTML entities instead.

(Try this here: http://codepad.viper-7.com/dfFMvW ; This page is in ISO-8859-1, if you send non-ISO-8859-1 characters in the input, they are sent as HTML entities.)


To avoid this you have to use a different encoding, like UTF-8.

Add this header in your <head> tag:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

Or do this in your PHP before printing anything:

header('Content-Type: text/html; charset=UTF-8');

And make sure your database uses UTF-8 too.


You can convert your database to UTF-8 by doing this:

ALTER DATABASE your_database CHARACTER SET utf8;
-- for each table:
ALTER TABLE some_table CONVERT TO CHARACTER SET utf8;

And after you connect to the database, send this query:

SET NAMES UTF8;
Arnaud Le Blanc
  • 95,062
  • 22
  • 198
  • 192
1

You dont need to html escape those characters as long as you have a UTF* table, and you do.

Simply make sure that the table is UTF8, that the connection is utf8, and the browser reads the texts as utf8.

  • for mysql see SET CHARACTER SET, SET NAMES, SET COLLATION_CONNECTION
  • for html use <meta content="text/html;charset=UTF-8" http-equiv="Content-Type" /> and the according http headers, if needed
Quamis
  • 10,621
  • 12
  • 48
  • 63