0

I am running following code to select and change text language. But When I am selecting my regional language then Its showing something like this. You can see the example here

Example Link

आपके इनबॉकà¥à¤¸ में 36 संदेश है.जिसमे आपने 4 नहीं पà¥à¥‡ है

My Code is ..

<?php
$lang=$_POST['lang'];
if($lang=='hindi')
{
printf(file_get_contents("hindi.txt"),36,4);
}
if($lang=='english')
{
printf(file_get_contents("template.txt"),36,4);
}
?>
<form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
<select name="lang">
<option value="hindi">Hindi</option>
<option value="english">English</option>
</select>
<input type="submit"/>
</form>
Akash Sharma
  • 801
  • 1
  • 9
  • 19

2 Answers2

0

This answer is useful when encoding the actual file doesn't help: How to set UTF-8 encoding for a PHP file

The answer above sends a manual over-riding header to the browser to tell it that it should be displaying as UTF-8.

Basically just make sure you're saving all of your .php files as UTF-8 encoded, the same goes for making sure all database tables and forms are encoded in UTF-8 - otherwise you'll still get odd characters appearing.

Editors like Notepad++ (On Windows) have a setting to make all new documents UTF-8 by default - might be worth taking a look at your editor and seeing if there is also an option - saves hassle in future (if you forget - been there and done that).

Community
  • 1
  • 1
Paul
  • 45
  • 1
  • 9
0

You should use the

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

tag in your html head section. Ii you are using only raw php to generate the output then use this meta tag like that -

<!DOCTYPE html>     
<html>
<head><title>Your Page Title here</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
   $lang=$_POST['lang'];
   if($lang=='hindi')
   {
   printf(file_get_contents("hindi.txt"),36,4);
   }
   if($lang=='english')
   {
   printf(file_get_contents("template.txt"),36,4);
   }
   ?>
   <form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
   <select name="lang">
   <option value="hindi">Hindi</option>
   <option value="english">English</option>
   </select>
   <input type="submit"/>
   </form>
</body>
</html>
fatih
  • 330
  • 8
  • 17