Supported Versions: PHP 5, PHP 7, PHP 8
Generate URL-encoded query string
<?php http_build_query( array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $encoding_type = PHP_QUERY_RFC1738): string
<?php public static function query($array)
{
return http_build_query($array, '', '&', PHP_QUERY_RFC3986);
}
<?php return $request->getParsedBody();
})->middleware(MergeDataMiddleware::class);
$response = $this->withoutExceptionHandling()->get('test-route?'.http_build_query([
'sent' => 'sent-data',
'overridden' => 'overridden-sent-data',
]));
$response->assertOk();
$response->assertExactJson([
<?php return $request->getParsedBody();
})->middleware(MergeDataMiddleware::class);
$response = $this->getJson('test-route?'.http_build_query([
'sent' => 'sent-data',
'overridden' => 'overridden-sent-data',
]), [
'content-type' => 'application/json',
]);
<?php return $request->getParsedBody();
})->middleware(MergeDataMiddleware::class);
$response = $this->getJson('test-route?'.http_build_query([
'sent' => 'sent-data',
'overridden' => 'overridden-sent-data',
]));
$response->assertOk();
$response->assertExactJson([
<?php $query = array_merge($query, ['redirect' => static::$redirect]);
}
return explode('?', $url)[0].'?'.http_build_query($query);
return $url;
}
<?php public function addToCartUrl($site, $statamic, $addons)
{
return 'https://statamic.com/cart/bulk-add?'.http_build_query([
'site' => $site->key(),
'statamic' => ! $statamic->valid(),
'products' => $addons->reject->valid()->map->addon()->map(function ($addon) {
$product = $addon->marketplaceId();
if ($edition = $addon->edition()) {
$product .= ':'.$edition;
}
return $product;
})->implode(','),
]);
}
}
<?php unset($queryAssociativeArray[$params[0]]);
$value = $url.(empty($queryAssociativeArray) ? '' : '?'.http_build_query($queryAssociativeArray)).$anchor;
}
return $value;
<?php $queryAssociativeArray[$params[0]] = $params[1] ?? '';
$value = "{$url}?".http_build_query($queryAssociativeArray).$anchor;
}
return $value;
<?php $params = array_merge($params, ['site' => $site]);
return $this->getJson($url.'?'.http_build_query($params));
}
private function mockTextFieldtype()
<?php 'http' => array(
'method' => 'POST',
'header' => array('Content-type: application/x-www-form-urlencoded'),
'content' => http_build_query($params, '', '&'),
'timeout' => 3,
),
);
<?php 'https://api.bitbucket.org/2.0/repositories/%s/%s?%s',
$this->owner,
$this->repository,
http_build_query(
array('fields' => '-project,-owner'),
'',
'&'
)
);
$repoData = $this->fetchWithOAuthCredentials($resource, true)->decodeJson();
<?php $resource = sprintf(
'%s?%s',
$this->tagsUrl,
http_build_query(
array(
'pagelen' => 100,
'fields' => 'values.name,values.target.hash,next',
'sort' => '-target.date',
),
'',
'&'
)
);
$hasNext = true;
while ($hasNext) {
<?php $resource = sprintf(
'%s?%s',
$this->branchesUrl,
http_build_query(
array(
'pagelen' => 100,
'fields' => 'values.name,values.target.hash,values.heads,next',
'sort' => '-target.date',
),
'',
'&'
)
);
$hasNext = true;
while ($hasNext) {
<?php $headers = array('Content-Type: application/x-www-form-urlencoded');
$apiUrl = $originUrl;
$data = http_build_query(array(
'username' => $username,
'password' => $password,
'grant_type' => 'password',
), '', '&');
$options = array(
'retry-auth-failure' => false,
'http' => array(
<?php parse_str($queryString, $queryParameters);
return http_build_query($queryParameters);
}