use Drupal\Core\Url; $url = Url::fromUri('internal:/node/123'); $url->setOption('query', ['sort' => 'desc', 'filter' => 'status']); $built_url = $url->toString();
use Drupal\Component\Utility\UrlHelper; $url = 'https://example.com/path/?key1=value1&key2=value2#fragment'; $parsed_url = UrlHelper::parse($url);
use Drupal\Core\Url; $url = Url::fromUri('internal:/user/123'); $secure_url = $url->setOption('https', TRUE)->toString();This code creates a URL for a Drupal user with ID 123, and sets the "https" option to true, so that the URL is generated with the "https" scheme instead of "http". The PHP Drupal URL library is a part of the Drupal core package, which means it comes with the Drupal installation by default.