Trying to execute the request through the script with the Atom feed:

foreach($xml->channel->item as $item) { global $chatID; $description = $item->description; $description = html_entity_decode($description); $description = strip_tags($description); var_dump($description); $sendto = API_URL."sendmessage?chat_id=".$chatID."&text=".$description; file_get_contents($sendto); } 

Issues 400 Bad Request: PHP Warning: file_get_contents("текст запроса") . I take the request text from the terminal, copy it to the browser’s address bar, the request is executed, the message arrives, but all Cyrillic characters are replaced with codes of the form: \u041f\u0440\u0438\u0432 and so on. I understand this is a problem with the encoding, I tried these solutions:

 //$description = mb_convert_encoding($description, 'utf-8', 'utf-8'); //$description = mb_convert_encoding($description,'CP1250','Unicode'); //$description = mb_convert_encoding($description, "UTF-8", "auto");Тол 

Zero sense. Who faced a similar, tell me how to solve this problem?

  • So you have a problem with 400 Error? or a problem with encodings? or both? - Arsen
  • @ Arsen I have a problem with the encoding, because of which the request is not sent. - Straight Edge

2 answers 2

The URL uses url coding , and not at all "bare characters" translated UTF-8 or UTF16.

Use the urlencode function.

  • Yes, that's it. Thank! - Straight Edge

When using file_get_contents use headers can help.

 $ opts = array (
   'http' => array (
     'method' => "GET",
     'header' => "Accept-language: ru \ r \ n".
               "Cookie: foo = bar \ r \ n"
   )
 );

 $ context = stream_context_create ($ opts);

 $ file = file_get_contents ('http://www.vashresurs.ru/', false, $ context);

If the problem with the encoding, try using urlencode($str);