Curl::format_get( string $url, array|object $data ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Format a URL given GET data

Parameters

$urlstringrequired
Original URL.
$dataarray|objectrequired
Data to build query using, see https://www.php.net/http_build_query

Return

string URL with data

Source

 * @param array|object $data Data to build query using, see https://www.php.net/http_build_query
 * @return string URL with data
 */
private static function format_get($url, $data) {
	if (!empty($data)) {
		$query     = '';
		$url_parts = parse_url($url);
		if (empty($url_parts['query'])) {
			$url_parts['query'] = '';
		} else {
			$query = $url_parts['query'];
		}

		$query .= '&' . http_build_query($data, '', '&');
		$query  = trim($query, '&');

		if (empty($url_parts['query'])) {
			$url .= '?' . $query;
		} else {
			$url = str_replace($url_parts['query'], $query, $url);
		}
	}

User Contributed Notes

You must log in before being able to contribute a note or feedback.