?PHP?,?????urlencode?????????????:
- ??
http_build_query()
??:???????????????URL????????????????????????????:
$array = [ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value with spaces', ]; $encoded_string = http_build_query($array);
- ?????????:??????????????,???????(???????)????????
http_build_query()
???????????,???????????????????:
$array = [ 'key1' => 'value1" & key2', 'key2' => 'value2\'', ]; // ????????? $array = array_map(function ($value) { return str_replace(['"', "'"], ['\"', "\\'"], $value); }, $array); $encoded_string = http_build_query($array);
- ???????:?????????????????,?????
http_build_query()
????????????????:
$array = [ 'key3' => 'value with spaces', 'key1' => 'value1" & key2', 'key2' => 'value2\'', ]; // ?????? ksort($array); $encoded_string = http_build_query($array);
- ???????:?????????????????????,????
parse_str()
???????????????:
$encoded_string = 'key1="value1"+&+key2&key2='value2'&key3= value+with+spaces'; // ??????? parse_str($encoded_string, $decoded_array);
????????,??????PHP??????urlencode??????????