PHP http_build_query()

1 개요[ | ]

PHP http_build_query()
  • URL 인코딩된 쿼리 문자열을 생성하는 PHP 함수

2 예시[ | ]

PHP
Copy
$params = [
	'foo' => 'bar',
	'baz' => 'boom',
	'cow' => 'milk',
	'php' => 'hypertext processor',
];
echo http_build_query($params); # foo=bar&baz=boom&cow=milk&php=hypertext+processor
Loading

한글도 잘된다.

PHP
Copy
$params = [
	'foo' => '한글',
	'bar' => '테스트',
];
echo http_build_query($params); # foo=%ED%95%9C%EA%B8%80&bar=%ED%85%8C%EC%8A%A4%ED%8A%B8
Loading

배열도 잘된다.

PHP
Copy
$params = [
	'hello' => 'world',
	'numbers' => [1, 2, 3],
];
echo http_build_query($params); # hello=world&numbers%5B0%5D=1&numbers%5B1%5D=2&numbers%5B2%5D=3
Loading
PHP
Copy
$params = [
	'hello' => 'world',
	'names' => ['한놈', '두시기', '석삼'],
];
echo http_build_query($params); # hello=world&names%5B0%5D=%ED%95%9C%EB%86%88&names%5B1%5D=%EB%91%90%EC%8B%9C%EA%B8%B0&names%5B2%5D=%EC%84%9D%EC%82%BC
Loading

3 같이 보기[ | ]

4 참고[ | ]