How to display non english characters in php?
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 Arab开发者_如何学Cic 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;
?>
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;
You have to use unicode encoding in your pages and scripts.
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).
精彩评论