File_put_contents encoding used on web servers?

I try to use file_put_contents (and file_get_contents ) with UTF-8 ¥ after this stackoverflow post: How to write a file in UTF- 8 format? which uses:

 $data = mb_convert_encoding($data, 'UTF-8', 'OLD-ENCODING'); 

This has not been well explained since it causes an error:

 mb_convert_encoding(): Illegal character encoding specified 

So, 'OLD-ENCODING' was just the placeholder they used. The question I have is what encoding should I change? ASCII or ISO-8859-1? What encoding do most web hosts use? Does it matter?

When I open the file, I will receive the character correctly only if I have my own notebook with UTF-8 encoding. If I open it with a different character set, it will appear with a “ ? ”.

+6
source share
2 answers

Try without the third parameter.

 $str = mb_convert_encoding($str, "UTF-8"); 

Or auto :

 $str = mb_convert_encoding($str, "UTF-8", "auto"); 

Additional information and examples: http://php.net/manual/function.mb-convert-encoding.php

+4
source

mb_convert_encoding($data, 'UTF-8', mb_detect_encoding($data));

mb_detect_encoding

+1
source

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


All Articles