2017-03-02 38 views
1

我有一個這樣的形式:如何編碼從html表單獲取參數?

<form action="/web/" method="get"> 
<input type="search" name="keyword_search_query"> 
<input type="submit" value="Search…"> 
</form> 

這是我的網站搜索表單。

將這些數據編碼到搜索查詢中以避免意外行爲的正確/常用方法是什麼?

例如,在其中一個輸入中使用&將切斷搜索查詢。我應該如何逃避這些角色?

P.S. Google如何做到這一點?

+0

的可能的複製[如何正確URL編碼在PHP中的字符串?](http://stackoverflow.com/questions/4744888/how-to-properly-url-encode-a -string-in-php) –

回答

0

用戶encodeURI(data);編碼

+0

什麼用戶禁用了JavaScript? – David

+1

你正在使用PHP,所以使用PHP函數。請參閱http://stackoverflow.com/questions/4744888/how-to-properly-url-encode-a-string-in-php。 –

+0

@David您可以讓用戶啓用Javascript,或者您可以使用PHP進行驗證。 –