PHP UTF-8 to Windows command line encoding

前端 未结 4 1203
广开言路
广开言路 2020-12-09 04:50

Everything is in the question : I have a Php script that is a UTF-8 file. In this script I want to do this :

  
4条回答
  •  醉话见心
    2020-12-09 05:56

    Try this another one. It's working with Russian encoding, I hope it will work with French:

    class ConsoleHelper
    {
        /**
         * @var boolean
         */
        private static $isEncodingSet = false;
    
        /**
         * @param string $message
         * @return string
         */
        public static function encodeMessage($message)
        {
            $isWindows = (DIRECTORY_SEPARATOR == '\\');
            if ($isWindows) {
                if ( ! self::$isEncodingSet) {
                    shell_exec('chcp 866');
                    self::$isEncodingSet = true;
                }
                $message = iconv('utf-8', 'cp866', $message);
            }
            return $message;
        }
    }
    

提交回复
热议问题