我正在将文本从 ios 发送到 php 并将其保存在 sql 数据库中。 但是像“äöü”这样的变音符号被保存为\344 等。
我不知道我能做什么...
这是我的步骤:
在 xcode 中:
NSData *data = [[_textInput getText] dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *post = [[NSString alloc] initWithFormat:@"&text=%@" goodValue];
NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString * postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://website.de/test.php"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
在 PHP 中:
$text = $_POST['text'];
$result = dbquery("INSERT INTO test (text) VALUES ('$text')");
这让我很生气 -.-,我怎样才能将变音符号从 ios 发送到 php??
最佳答案
你不应该使用 NSASCIIStringEncoding
。请改用 NSUTF8StringEncoding
。
NSData * postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
关于php - 从 ios 到 php 的变音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18289955/