?PHP?,urlencode()
??????????URL??????????????,????????(???????)?????,????????:
- ??
array_map()
??????????????urlencode()
??:
$array = array('hello world', 'this is a "quote"', 'another example'); $encoded_array = array_map('urlencode', $array); $result = implode('&', $encoded_array); echo $result; // ??: hello world&this is a "quote"&another example
- ?????????????,????
http_build_query()
???????????????:
$array = array( 'key1' => 'value1', 'key2' => 'value2 with spaces', 'key3' => 'value"with"quotes', ); $query_string = http_build_query($array); echo $query_string; // ??: key1=value1&key2=value with spaces&key3=value"with"quotes
- ??????????,????????????????????????????:
function array_urlencode_recursive($array) {
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result[$key] = array_urlencode_recursive($value);
} else {
$result[$key] = urlencode($value);
}
}
return $result;
}
$nested_array = array(
'key1' => 'value1',
'key2' => array(
'subkey1' => 'subvalue1',
'subkey2' => 'subvalue"with"quotes',
),
);
$encoded_nested_array = array_urlencode_recursive($nested_array);
$result = implode('&', $encoded_nested_array);
echo $result; // ??: key1=value1&key2[subkey1]=subvalue1&key2[subkey2]=subvalue"with"quotes
????????????????????????