? PHP ?,urlencode()
??????????? URL ????
-
??
urlencode()
? GET ??????: ????????? GET ????? URL ?,????urlencode()
????????????????????????,?????????????$query = "search query"; $encodedQuery = urlencode($query); $url = "https://example.com/search?q={$encodedQuery}";
-
??
http_build_query()
????????????:http_build_query()
??????????????????????,??????????? URL?$params = [ 'key1' => 'value1', 'key2' => 'value with spaces', ]; $encodedParams = http_build_query($params); $url = "https://example.com/api?" . $encodedParams;
-
??
urlencode()
? URL ????????: ?????? URL ????????,?????urlencode()
?????????$category = "????"; $encodedCategory = urlencode($category); $url = "https://example.com/products/{$encodedCategory}/";
-
??
rawurlencode()
? URL ???????????: ?urlencode()
??,rawurlencode()
????????? URL ?????????,rawurlencode()
????????+
,?????$path = "path with spaces"; $encodedPath = rawurlencode($path); $url = "https://example.com/{$encodedPath}/";
-
?? URL ??: ????? URL ????????,????
urldecode()
???$encodedParam = "电子产品"; $decodedParam = urldecode($encodedParam); echo $decodedParam; // ??:????
????????,????? PHP ????? urlencode()
???????? URL ???