从C#Windows应用程序的PHP页面获取utf8字符串 [英] get utf8 string from PHP page in C# windows application
问题描述
我有一个用C #
编写的 Windows应用程序,并且有一个网络侦听器和一个PHP
页面,它们从mysql
数据库中获取一个字符串,并通过套接字将该字符串发送到带有以下代码的Windows应用程序:
I have a Windows application that write in C#
and have a network listener and a PHP
page that get a string from mysql
database and send that string via a socket to windows application with this code:
$remote_ip='192.168.5.133';//this is the ip of computer that run windows app
ini_set('display_errors',off);
$sh=fsockopen($remote_ip,6000,$en,$en,1);
ini_set('display_errors',on);
fputs($sh,$Text_To_Send_Windows_Application);
$test_keycard=fread($sh,2);
fclose($sh);
当我在Windows应用程序中收到字符串时,会出现类似这样的内容:
When I receive the string in windows application, there is something like :
¨ÛستÛکاسÙÙدÙزارÙسÛصدÙÙدÙÙ¾Ùج
¨Ûست Ù ÛÚ© اسÙÙد Ùزار ٠سÛصد Ù ÙÙد Ù Ù¾Ùج
我尝试将此代码转换为C#格式的utf8格式
I try to convert this code to utf8 format in C# whit this code
string plainText = UTF8Encoding.UTF8.GetString(UTF8encodes);
但它不会返回原始字符串.
But it not return original string.
有人可以告诉我如何获取从PHP
页发送的原始字符串吗?
Could anyone tell me how I get original string that send from my PHP
page?
推荐答案
您要阿拉伯语吗?包括ست
等吗?你有Mojibake.参见 此 进行更多讨论.
You are expecting Arabic? Including ست
etc? You have Mojibake. See this for more discussion.
不要使用任何编码/解码功能,只会使情况变得更糟.
Do not use any encoding/decoding functions, it only makes things worse.
您需要在连接中添加以下内容:
You need something like this in the connection:
id=my_user;password=my_password;database=some_db123;charset=utf8;
(或utf8mb4
)
如果事实证明您具有双重编码",请参见 此
If it turns out that you have "double encoding", see this
这篇关于从C#Windows应用程序的PHP页面获取utf8字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!