如何对 URI 中 $search 变量的 GET 请求进行编码(示例:Android 和 Corp)以获取 (Android%2Band%2BCorp) 而不是 (Android+and+Corp)?Form_ <form action="search.php" method="GET"> <input type="text" name="search" placeholder="Search.." id="myInput" onkeyup="filterFunction()"> <input value="1" name="chank" id="one" type="radio" checked /> <label for="one" class="switch__label">1</label> <input value="2" name="chank" id="two" type="radio" /> <label for="two" class="switch__label">2</label> </form>search.php_$search=$_GET['search'];$channel=$_GET['chank'];$page=$_GET['page'];include "conf/info.php";$title = 'Result | '.$search;include "header.php";include "api/api_search.php";GET_ api.php$cs = curl_init();curl_setopt($cs, CURLOPT_URL, "".$home."".$vapi."/search/".$chank."?api_key=".$key."&language=".$lang."&query=".$search."&page=".$page."");curl_setopt($cs, CURLOPT_RETURNTRANSFER, TRUE);curl_setopt($cs, CURLOPT_HEADER, FALSE);curl_setopt($cs, CURLOPT_HTTPHEADER, array("Accept: application/json"));$response = curl_exec($cs);curl_close($cs);$search = json_decode($response);但我的地址栏中仍然显示“+”而不是真正的“%2B”
1 回答
忽然笑
TA贡献1806条经验 获得超5个赞
看起来 curl 正在将您的字符串从 _GET(使用 +)编码为 %2b。在构建 curlopt url 之前,您可以使用 urldecode() 获取“原始”:
$s = 'some+cool+string';
echo $s . PHP_EOL; // some+cool+string
echo urlencode($s) . PHP_EOL; // some%2Bcool%2Bstring
echo urldecode($s) . PHP_EOL; // some cool string
- 1 回答
- 0 关注
- 171 浏览
添加回答
举报
0/150
提交
取消
