开发者

Escape character in NSString

I have encounter a problem. I have a NSString and I would like to send this string to server to insert to database. But I have problem when NSString is (for example):

This isn't a student.

And this st开发者_开发技巧ring is sent to server side with this script:

$value = $_POST["stringvalue"]

insert into stringtable (stringvalue) values ('$value');

Because of "isn't" part, the insert query can not run and fail.

Now I would like to escape characters, that means "isn't" will become "isn\'t" so that I can insert to database. I would like to ask how can I do it?

Thank you.


Don't rely on input sanitation methods, it is best to insert data using only parameterised statements. Learn more about Bobby Tables and more specifically how to avoid it in PHP.

One particular problem with input sanitation is that you must do it before every insert, and sometimes it may be done twice accidentally, and so on. Simply used parameterised statements and it will be easier in the long run.


This might help you

Replace " " character in an NSString with "\ " (to create a Unix path)


I guess this is a problem of PHP instead of iPhone SDK?


You can use these PHP methods on the server side :

$value = addslashes($_POST["stringvalue"]);

To add slashes on your $value (addslashes)

$value = html_special_chars($_POST["stringvalue"]);

To escape all special chars. addslashes

It's not an iPhone problem I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜