开发者

HTML Forms - removing slashes safely

I'm using a web form to store user input into a MySQL DB, using $_POST.

I have noticed that开发者_开发知识库 once textarea fields area read, slashes are inserted automatically to escape some characters.

As I need to manipulate text before storing, I thought about using stripslashes, however I have discovered that it may garbage text, if Japanese or other asiatic character sets are used.

Is there a proper way to do the job (remove slashes) safely?


Turn off magic quotes in your PHP settings. The feature is deprecated anyway.


If you don't want to disable magic quotes (even though they won't be working anymore in PHP 6.0 as they were deprecated in 5.3), you can use this code

$txt = $_POST['txt'];
if(get_magic_quotes_gpc())
    $txt = stripslashes($txt);

this way stripslashes would only be enabled when your PHP module has magic quotes enabled or ignore it otherwise

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜