📜 ⬆️ ⬇️

Problem UTF-8 Byte Order Mark or Cyrillic Quacking

Faced the problem of incorrect display of Cyrillic fonts in the browser, or rather the browser incorrectly determined the encoding. A brief analysis showed that this inconvenience manifests itself only when the ZF debug plugin is enabled. Throwing a glance at the source code of the page saw that the plug-in connects its styles and scripts immediately after the opening <head> , that is, before the meta tag with information about the page encoding, which is probably not entirely correct.



To fix the situation, you need to correct the file library \ ZFDebug \ Controller \ Plugin \ Debug.php as follows (highlighted in black)
')
protected function _headerOutput ( ) {
$ collapsed = isset ( $ _COOKIE [ 'ZFDebugCollapsed' ] ) ? $ _COOKIE [ 'ZFDebugCollapsed' ] : 0 ;

return ( '
<style type = "text / css" media = "screen">
...
</ script> </ head> ' ) ;
}


protected function _output ( $ html )
{
...
$ response -> setBody ( preg_replace ( '/ ( <\ / head> ) / i' , '$ 1' . $ this -> _headerOutput ( ) , $ response -> getBody ( ) ) ) ;
...
}

Everything, now <meta http-equiv="content-type" content="text/html; charset=utf-8" /> will appear immediately after the opening <head> .

ps The problem is also solved if the BOM is forced to be specified at the beginning of the file, but, for example, PHP Storm cannot (at the moment) save it. However, BOM is not necessary for browser applications, it is even redundant, based on the document " Use of BOM is not required for UTF-8 "

Source: https://habr.com/ru/post/103925/


All Articles