2013-05-04 36 views
0

我遇到了將輸入保存到我的數據庫的問題。在斜線上輸入崩潰

我我的字符串保存到我的數據庫爲:

mysql_real_escape_string($my_string) 

然後,我閱讀,我用這個地方的字符串輸入:

stripslashes($my_string) 

的一點是,如果設置了雙斜槓輸入我的字符串,輸入崩潰像這樣:

<input maxlength = "150" type="text" name = "my_string12" value = "hello "this is" a test" class="input-medium"/> 

謝謝。

+0

變化 '這是' – matzone 2013-05-04 11:17:13

+0

這應該工作。但我不能告訴我的用戶使用單引號而不是雙斜槓。 – 2013-05-04 11:19:16

回答

0

如果該值作爲PHP變量,那麼你必須修剪它..

使用裁剪功能:

$str = 'hello "this is" a test'; 
echo trim($str, '"'); // hello this is a test 

here

0

保羅回答,您可以使用

<?php echo addslashes('hello "this is" a test'); // hello \"this is\" a test ?>

an stripslashes將其刪除

<?php echo stripslashes('hello \"this is\" a test'); // hello "this is" a test ?>

或只需鍵入像這樣

value = 'hello "this is" a test'value = "hello 'this is' a test"