views:

256

answers:

3

Hi guys

I've a basic question in php:

I've 2 files: An html form with a textarea and a php file. All I want is to print the text the user types after submit is pressed. It all goes well when only english characters are typed but I get gibberish when I type arabic or chinese for instance. Is there a way to display all the characters?

Here is the code of the php file:

  <?php
 $txt = $_GET['toTranslate'];
 echo $txt;
?>
A: 

You have to use unicode encoding in your pages and scripts.

silent
+3  A: 

Please try to add

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

or Add set as html and set

echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
echo $txt;
S.Mark
A: 

Make sure the page with the form and the page with the output use the same character set (UTF-8 explicitly set with header() is the safest choice). By default PHP would return exactly what it receives, no matter what character set it is, unless you do some manipulation with that text string (in this case check out the multibyte string functions).

djn