What can be problem with encoding in PHP for some operations?

Problems arose when integrating with some services - the team json_encode returns an empty string when encoding the array in json. During debugging it turned out that part of the data in the array in the encoding ISO-8859-1.
The same happens while writing data file.
The array is formed from two sources - data from the database and the data sehardcore in the code files in UTF-8.

Two different script behave differently - in one the data that is added in code and written to a file using file_put_contents the final file in UTF-8, and the data from the database in ISO-8859-1.
Such an array while trying to retrieve the json is converted to the empty string.
In another all the data are written to the file in ISO-8859-1, and is displayed in the browser as UTF-8 and is converted into json.

That ISO-8859-1 learned after recoding on the website of Lebedev.

In the Php settings everywhere UTF-8. ISO-8859-1 generally does not appear anywhere.
Don't even know where to dig.

Tag Bitrix despite the fact that the site on Bitrix, but I think it does not matter.
April 19th 20 at 12:24
1 answer
April 19th 20 at 12:26
Solution
the data from the database in ISO-8859-1.


not set encoding for database
Forgot to write - set. Everything is fine with it. Compare too.
Everywhere explicitly set to utf-8

On the page that the browser displays in utf-8.

Ie is such garbage:
$arOrder = CSaleOrder::GetByID(70);
$obBasket = \Bitrix\Sale\Basket::getList(array('filter' => array('ORDER_ID' => 70)));
$arOrder['TEST'] = 'Test';
while($bItem = $obBasket->Fetch()){
 $arOrder['BASKET_ITEMS'][] = $bItem;
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/orderhandler.txt',print_r($bItem,true),FILE_APPEND);
}


file_put_contents($_SERVER['DOCUMENT_ROOT'].'/df.txt',print_r($arOrder,true));
print('<-- --<pre>'.print_r($arOrder,true).'</pre>-->');
die('<-- --<pre>'.print_r(json_encode($arOrder),true).'</pre>-->');


on the page normally displays the contents of $arOrder, and to file orderhandler.txt everything is written in 8859-1 - layne_Casper40 commented on April 19th 20 at 12:29
Noted decision because it forced me to dig in I will shift the database. Okazyvatsya had to install:
SET sql_mode="
SET innodb_strict_mode=0

If you know why this helped, enjoy reading. - layne_Casper40 commented on April 19th 20 at 12:32

Find more questions by tags PHP