简体   繁体   English

如何编码NSString以将其发送到PHP iOS

[英]How do I encode a NSString to send it to a PHP iOS

I need to send a NSString to a PHP file that goes into a MySQL database. 我需要将NSString发送到进入MySQL数据库的PHP文件。 The problem that I have is with especial characters like "é". 我遇到的问题是使用特殊字符(例如“é”)。 When I get the string (from the Facebook SDK for iOS) it comes like this: "Thenáme Thesurnamé", for example. 当我从iOS的Facebook SDK获得字符串时,它像这样:“ThenámeThesurnamé”。

I send it to a PHP on a server using unicode as charset (I also tried with utf8), but in the database it appears with "é" instead of "é". 我将其发送到使用Unicode作为字符集的服务器上的PHP(我也尝试使用utf8),但是在数据库中它显示为“é”而不是“é”。

The encoding of the database is utf8_unicode_ci 数据库的编码为utf8_unicode_ci

您始终可以在html中使用“ &”号来编码此类字符。

试试这个代码:

NSString *resStr = [[NSString alloc] initWithCString:[srcStr cStringUsingEncoding:[NSString defaultCStringEncoding]] encoding:NSMacOSRomanStringEncoding];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM