Hello. Actually, I had a problem when applying string functions (transformations) to strings containing Russian characters and then writing the result to an HTML file. For example, I do this:

$str = 'строка строка страница страница'; $str2 = strrev($str); $f=fopen("htmlik.html","a+"); fputs($f,$str2); fclose($f); 

And the question marks, diamonds, small squares, in general, everything except the fact that there really should be are written to the file ... Already in .htaccess it climbed and changed the default Russian encoding setting there, but nothing helps! Please help me ... thanks ....

    1 answer 1

    Option 1:

    The encoding of the source file is single-byte (windows-1251 for example).

    The htmlik.html encoding will also be windows-1251

    Option 2:

    Source file encoding is multibyte (utf-8 for example)

    In htmlik.html there will be bad text, because strrev does not work correctly with multibyte characters. As an option to use

     function mb_strrev($str, $encoding='UTF-8'){ return mb_convert_encoding( strrev( mb_convert_encoding($str, 'UTF-16BE', $encoding) ), $encoding, 'UTF-16LE'); } 

    instead of strrev(); and everything will be OK.

    • The second method helped! Thank you very much!!! - AseN