Home » Php » php – How to add a literal quote in Laravel's .env file?

php – How to add a literal quote in Laravel's .env file?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’d like to add a string value to my .env file that contains quotes like so.

APP_NAME="Hacking"

Laravel assumes the quotes are being used to define the string, but I want the literal quote in the string.

I’ve also tried the following.

APP_NAME='"Hacking"'

APP_NAME=\"Hacking\"

APP_NAME="\"Hacking\""
How to&Answers:

Try this:

APP_NAME='""Hacking""'

or this:

APP_NAME="\"\"Hacking\"\""

The dotenv library removes the outer layer of single or double quotes when it sets the environment variable:
https://github.com/vlucas/phpdotenv/blob/fa1a24d/src/Loader.php#L249

Laravel’s env() helper removes the outer layer of double quotes when it retrieves the variable:
https://github.com/laravel/framework/blob/2ab2fc6/src/Illuminate/Support/helpers.php#L613