I'm searching for a method in PHP that generates a full query URL by passing a base URL (which could already include a query string) plus additional parameters.
I know that I could check if the URL contains a "?" and if so append with "&", otherwise append with "?". The question here is, if PHP has such a method on board?
I'll give you an example:
// Only works if $baseUrl not includes parameters
public function buildQuery($baseUrl, array $params) {
return $baseUrl . '?' . http_build_query($params);
}
// But what if I do this?
$url = $this->buildQuery('https://my.endpoint.com/fetch?subject=php', ['maxlength' => 10]);