如何为 URI 中的 $search 变量编码 GET 请求?
How do I encode a GET request for the $search variable in the URI?
如何对 URI 中 $search 变量的 GET 请求进行编码(示例:Android 和 Corp)以获取 (Android%2Band%2BCorp) 而不是 (Android+和+公司)?
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”
看起来 curl 正在将您的字符串从 _GET(带有 +)编码为 %2b。在构建 curlopt url:
之前,您可以使用 urldecode() 获取 'original'
$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
如何对 URI 中 $search 变量的 GET 请求进行编码(示例:Android 和 Corp)以获取 (Android%2Band%2BCorp) 而不是 (Android+和+公司)?
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”
看起来 curl 正在将您的字符串从 _GET(带有 +)编码为 %2b。在构建 curlopt url:
之前,您可以使用 urldecode() 获取 'original'$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