2013-05-30 28 views
1

我使用PHP來存儲一些會話變量以跟蹤用戶輸入到搜索表單中的內容,然後如果他們需要重新開始搜索,我們可以恢復這些內容。除了以下內容,這一切都運行良好。HTML文本輸入值包含引用標記

允許用戶使用雙引號將搜索字符串換行,該字符將在該字段上執行不同類型的搜索(完全匹配)。如果用戶輸入這樣的文本到文本搜索字段中的一個:

「心臟疾病」

的SEACH工程和值會被保留在PHP會話變量,但是當我們來到恢復它在做的時候再次搜索失敗。下面是恢復文本輸入的代碼:

<input type="text" id="condition" name="condition" value="<?php echo $conditionSearchValue; ?>"> 

我收集了雙引號是造成問題,因爲這將是:

<input type="text" id="condition" name="condition" value=""heart condition""> 

是否有恢復與雙引號的輸入方式標記我不知道?

感謝

回答

1
<input type="text" id="condition" name="condition" value="<?php print htmlentities($conditionSearchValue, ENT_QUOTES); ?>"> 

更多的文檔herehtmlentities信息。

+0

改爲使用[htmlspecialchars($ string,ENT_QUOTES,'utf-8')](http://php.net/manual/en/function.htmlspecialchars.php)。 – Xeoncross

+0

爲什麼?好點嗎? – Saturnix

+0

是的,它只編碼那些在HTML文檔中具有重要性的5個字符 - htmlentities試圖轉換更多。 – Xeoncross

相關問題