The putenv function of laravel-php cannot be used in Chinese.

Source: Internet
Author: User
If you know laravel, you can take a look at the above section. if you don't know about it, go straight to the split line ;. for any item in env, use MAIL_DRIVER as an example to change it to "my". use the env function to get the value normally. change it to "I" and use the env function to get the value normally; {code ...} other... if you know laravel, you can take a look at the above section. if you don't know about it, go straight to the split line below;

Any item in. env takes MAIL_DRIVER as an example.
Change to "my" and use the env function to get the value normally;
Changed to "I" and the env function won't be available;

MAIL_DRIVER = my var_dump (env (MAIL_DRIVER ''); // NULLMAIL_DRIVER = my var_dump (env (MAIL_DRIVER''); // My

Other Chinese characters, such as "good", will also encounter this situation;
I have to say that laravel is profound and profound. I have studied the env function source code;
The final problem is;
----------------------------------------------- Understand and do not understand the split line of the laravel framework ------------------------------------------------

Putenv ("PROJECT_NAME = my"); phpinfo ();

In phpinfo, Environment can be searched for PROJECT_NAME.

Putenv ("PROJECT_NAME = Me"); phpinfo ();

In phpinfo, Environment cannot find PROJECT_NAME.

Ask your friends. why? How can I set Chinese values without barriers?

Reply content:

If you know laravel, you can take a look at the above section. if you don't know about it, go straight to the split line below;

Any item in. env takes MAIL_DRIVER as an example.
Change to "my" and use the env function to get the value normally;
Changed to "I" and the env function won't be available;

MAIL_DRIVER = my var_dump (env (MAIL_DRIVER ''); // NULLMAIL_DRIVER = my var_dump (env (MAIL_DRIVER''); // My

Other Chinese characters, such as "good", will also encounter this situation;
I have to say that laravel is profound and profound. I have studied the env function source code;
The final problem is;
----------------------------------------------- Understand and do not understand the split line of the laravel framework ------------------------------------------------

Putenv ("PROJECT_NAME = my"); phpinfo ();

In phpinfo, Environment can be searched for PROJECT_NAME.

Putenv ("PROJECT_NAME = Me"); phpinfo ();

In phpinfo, Environment cannot find PROJECT_NAME.

Ask your friends. why? How can I set Chinese values without barriers?

I also tried it and found that as long as it is called in the cgi environmentPutenv ('Project _ NAME = drop ')And so on (four bytes, the same for Japanese kana ).falseIn the cli environment:

Region ~ $ Php-r "var_dump (putenv ('Project _ NAME = MY'); echo getenv ('Project _ name');" bool (true) me

I am also fascinated by the fact that Google cannot find a similar situation. I hope other people will have a good answer.

However, since the subject uses Laravelputenv, Just to get it.envYou can use the following tips:

In your own projecthelpers.phpTo add a new function (or another place where the custom help function is put:

if (! function_exists('menv')) {    /**     * Gets the value of an environment variable by getenv() or $_ENV.     *     * @param  string  $key     * @param  mixed   $default     * @return mixed     */    function menv($key, $default = null)    {        if (function_exists('putenv') && function_exists('getenv')) {            // try to read by getenv()            $value = getenv($key);            if ($value === false) {                return value($default);            }        } else {            // try to read from $_ENV or $_SERVER            if (isset($_ENV[$key])) {                $value = $_ENV[$key];            } elseif (isset($_SERVER[$key])) {                $value = $_SERVER[$key];            } else {                return value($default);            }        }        switch (strtolower($value)) {            case 'true':            case '(true)':                return true;            case 'false':            case '(false)':                return false;            case 'empty':            case '(empty)':                return '';            case 'null':            case '(null)':                return;        }        if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) {            return substr($value, 1, -1);        }        return $value;    }}

Define a new function for getting environment variables andconfig/AllenvReplacemenv(I tried$_ENV,$_SERVERWill not be affected)

For more information, see here. it was originally intended for some users not to useputenvAll you have done is

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.