如何编码从html表单获取参数?
我有一个这样的形式:如何编码从html表单获取参数?
<form action="/web/" method="get">
<input type="search" name="keyword_search_query">
<input type="submit" value="Search…">
</form>
这是我的网站搜索表单。
将这些数据编码到搜索查询中以避免意外行为的正确/常用方法是什么?
例如,在其中一个输入中使用&
将切断搜索查询。我应该如何逃避这些角色?
P.S. Google如何做到这一点?
用户encodeURI(data);
编码
什么用户禁用了JavaScript? – David
你正在使用PHP,所以使用PHP函数。请参阅http://*.com/questions/4744888/how-to-properly-url-encode-a-string-in-php。 –
@David您可以让用户启用Javascript,或者您可以使用PHP进行验证。 –
的可能的复制[如何正确URL编码在PHP中的字符串?](http://*.com/questions/4744888/how-to-properly-url-encode-a -string-in-php) –