如何在php中显示非英文字符?

发布于 2024-08-16 22:12:14 字数 264 浏览 0 评论 0原文

我有一个关于 PHP 的基本问题:

我有 2 个文件:一个带有 Textarea 的 HTML 表单和一个 PHP 文件。我想要的只是在按下提交后打印用户输入的文本。当只输入英文字符时,一切都很顺利,但例如,当我输入阿拉伯语或中文时,我会得到乱码。有没有办法显示所有字符?

这是 PHP 文件的代码:

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

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;
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱给你人给你 2024-08-23 22:12:14

请尝试添加

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

或添加设置为 html 并设置

echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
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;
装迷糊 2024-08-23 22:12:14

您必须在页面和脚本中使用 unicode 编码。

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

楠木可依 2024-08-23 22:12:14

确保包含表单的页面和包含输出的页面使用相同的字符集(使用 header() 显式设置的 UTF-8 是最安全的选择)。默认情况下,PHP 将准确返回它收到的内容,无论它是什么字符集,除非您对该文本字符串进行一些操作(在这种情况下,请查看 多字节字符串 函数)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文