phpencodingutf-8cp1251

Troubles with cyrillic encoding in PHP MySQL site


Have a problem with the cyrillic encoding cyrillic data from mysql displayed correct, but when I add some cyrillic text on the page I get someting like this ывааапв

data in MySQl - utf8_general_ci

php file:

header('Content-Type: text/html; charset=windows-1251'); 

mysql_query('SET NAMES cp1251');

Solution

  • You're adding the text in utf-8, while your page in 1251.
    So, set your editor into Windows-1251 when adding text

    OR

    change your headers from 1251 to utf-8

    header('Content-Type: text/html; charset=utf-8'); 
    mysql_query('SET NAMES utf8');