get utf8 string from PHP page in C# windows applic

2019-08-17 08:20发布

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

When I receive the string in windows application, there is something like :

¨Ûست Ù ÛÚ© اسÙÙد Ùزار ٠سÛصد Ù ÙÙد Ù Ù¾Ùج

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.

Could anyone tell me how I get original string that send from my PHP page?

1条回答
戒情不戒烟
2楼-- · 2019-08-17 08:25

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;

(or utf8mb4)

If it turns out that you have "double encoding", see this

查看更多
登录 后发表回答