我正在从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')");
它让我生气-.-,我怎样才能将umlauts从ios发送到php?
答案 0 :(得分:2)
您不应该使用NSASCIIStringEncoding
。请改用NSUTF8StringEncoding
。
NSData * postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];