diff --git a/configuration/env_var_processors.rst b/configuration/env_var_processors.rst
index eba9f4a482c..fc512c84e8e 100644
--- a/configuration/env_var_processors.rst
+++ b/configuration/env_var_processors.rst
@@ -812,6 +812,56 @@ Symfony provides the following env var processors:
// config/services.php
$container->setParameter('typed_env', '%env(defined:FOO)%');
+.. _urlencode_environment_variable_processor:
+
+``env(urlencode:FOO)``
+ Urlencode the content of ``FOO`` env var. This is especially useful when
+ ``FOO`` value is not compatible with DSN syntax.
+
+ .. configuration-block::
+
+ .. code-block:: yaml
+
+ # config/packages/framework.yaml
+ parameters:
+ env(DATABASE_URL): 'mysql://db_user:foo@b$r@127.0.0.1:3306/db_name'
+ encoded_database_url: '%env(urlencode:DATABASE_URL)%'
+
+ .. code-block:: xml
+
+
+
+
+
+
+ mysql://db_user:foo@b$r@127.0.0.1:3306/db_name
+ %env(urlencode:DATABASE_URL)%
+
+
+
+ .. code-block:: php
+
+ // config/packages/framework.php
+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
+
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
+ use Symfony\Config\FrameworkConfig;
+
+ return static function (ContainerBuilder $container): void {
+ $container->setParameter('env(DATABASE_URL)', 'mysql://db_user:foo@b$r@127.0.0.1:3306/db_name');
+ $container->setParameter('encoded_database_url', '%env(urlencode:DATABASE_URL)%');
+ };
+
+ .. versionadded:: 7.1
+
+ The ``env(urlencode:...)`` env var processor was introduced in Symfony 7.1.
+
It is also possible to combine any number of processors:
.. configuration-block::
diff --git a/doctrine.rst b/doctrine.rst
index f17307108c1..b024c4e7a4c 100644
--- a/doctrine.rst
+++ b/doctrine.rst
@@ -59,10 +59,11 @@ The database connection information is stored as an environment variable called
If the username, password, host or database name contain any character considered
special in a URI (such as ``+``, ``@``, ``$``, ``#``, ``/``, ``:``, ``*``, ``!``, ``%``),
- you must encode them. See `RFC 3986`_ for the full list of reserved characters or
- use the :phpfunction:`urlencode` function to encode them. In this case you need to
- remove the ``resolve:`` prefix in ``config/packages/doctrine.yaml`` to avoid errors:
- ``url: '%env(DATABASE_URL)%'``
+ you must encode them. See `RFC 3986`_ for the full list of reserved characters.
+ You can use the :phpfunction:`urlencode` function to encode them or
+ the :ref:`urlencode environment variable processor `.
+ In this case you need to remove the ``resolve:`` prefix in ``config/packages/doctrine.yaml``
+ to avoid errors: ``url: '%env(DATABASE_URL)%'``
Now that your connection parameters are setup, Doctrine can create the ``db_name``
database for you: