如何在PHP中正确的URL编码一个string?
我在做一个search页面,在那里你键入一个search查询和表单提交到search.php?query=your query 。 什么PHPfunction是最好的,我应该使用编码/解码search查询?
对于URI查询使用urlencode / urldecode ; 对于其他任何使用rawurlencode / rawurldecode 。
urlencode和rawurlencode的区别在于
-
urlencode根据application / x-www-form-urlencoded (空间用+编码)进行编码 -
rawurlencode根据简单的百分比编码 (空间编码为%20)进行编码。
狡猾的urlencode()和urldecode() 。
但是,您不需要对出现在$_POST和$_GETvariables使用urldecode() 。