Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UrlHelper.php

function UrlHelper::compressQueryParameter

Compresses a string for use in a query parameter.

While RFC 1738 doesn't specify a maximum length for query strings, browsers or server configurations may restrict URLs and/or query strings to a certain length, often 1000 or 2000 characters. This method can be used to compress a string into a URL-safe query parameter which will be shorter than if it was used directly.

Parameters

string $data: The data to compress.

Return value

string The data compressed into a URL-safe string.

See also

\Drupal\Component\Utility\UrlHelper::uncompressQueryParameter()

4 calls to UrlHelper::compressQueryParameter()
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
Returns the JavaScript assets for the current response's libraries.
CssCollectionOptimizerLazy::optimize in core/lib/Drupal/Core/Asset/CssCollectionOptimizerLazy.php
Optimizes a collection of assets.
JsCollectionOptimizerLazy::optimize in core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php
Optimizes a collection of assets.
SettingsCommand::render in core/lib/Drupal/Core/Ajax/SettingsCommand.php
Implements Drupal\Core\Ajax\CommandInterface:render().

File

core/lib/Drupal/Component/Utility/UrlHelper.php, line 82

Class

UrlHelper
Helper class URL based methods.

Namespace

Drupal\Component\Utility

Code

public static function compressQueryParameter(string $data) : string {
    // Use 'base64url' encoding. Note that the '=' sign is only used for padding
    // on the right of the string, and is otherwise not part of the data.
    // @see https://datatracker.ietf.org/doc/html/rfc4648#section-5
    // @see https://www.php.net/manual/en/function.base64-encode.php#123098
    return str_replace([
        '+',
        '/',
        '=',
    ], [
        '-',
        '_',
        '',
    ], base64_encode(gzcompress($data)));
}
RSS feed
Powered by Drupal