By 03/02/2016 15 Comments

How display non-English characters in PHP from MySQL database?

  • In PHP it is possible to display Non-English characters in webpage from database(MySQL).
  • In PHP we can easily display all language’s characters which has been spoken in universe.
  • Unicode supports these all universe languages.

Step-1:

  • Set the character set/charset as utf8 and collation as utf8_general_ci to your MySQL database,table and each column of database table.

Step-2:

  • Write the following code in PHP immediately after mysqli_connect() statement .
  • Following PHP code makes able to MySQL database for accept or communicate with unicode characters. In other words it permanent sets the MySQL database connection as unicode (utf8).

mysqli_connect($host,$user,$pass,$dbname);
mysqli_set_charset($connection, "utf8"); // Notice this.

// OR

mysqli_query($connection, "SET NAMES utf8"); // this statement is optional (for client machine unicode support).


Step-3 (final):

  • Make a PHP file where you want to display Non-English characters. Write the following code in it.

// write following lines in head section. These lines tell to browsers "Please display/render Non-English characters correctly!"

//for HTML5


//for HTML 4 or less versions


// OR use PHP's built-in header function which works exactly same as above  statements work.

header('Content-Type: text/html; charset=utf-8');
// write database code which fetches Non-English data from MySQL database.






Posted in: PHP, Solutions

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .