电报键盘不显示非英语字符吗? [英] telegram keyboard not showing non English languages chracters?
问题描述
我正在尝试用波斯语编写php电报bot,这是非英语utf8语言. 当我尝试用波斯语向客户发送纯文本时,效果很好
I'm trying to write a php telegram bot in Persian which is a non English utf8 language. when I try to send plain text in Persian to my client it works perfectly ok
$array = [
"chat_id" => $chat_id,
"text" => $someNonEnglishText
];
$telegram->sendMessage($array);
但是当我尝试使用下面的代码发送键盘数据时,只会显示一些问号,例如????????????????在我的键盘按钮上
but when I try to send keyboard data with the code below it just show some question marks like ???????????????? on my keyboard buttons
$reply_markup = $telegram->replyKeyboardMarkup([
'keyboard' => $someNonEnglishkeyboard,
'resize_keyboard' => true,
'one_time_keyboard' => true
]);
$telegram->sendMessage([
'chat_id' => $updates[0]->getMessage()->getChat()->getId(),
'text' => $something,
'reply_markup' => $reply_markup
]);
我通过在终端中运行以下命令来完全确定我的机器人php文件是utf8 文件myfile.php 我得到答案: surveyBot.php:PHP脚本,UTF-8 Unicode文本
an I'm perfectly sure that my bot php file is utf8 by running the following command in terminal file myfile.php whilch I got the answer: surveyBot.php: PHP script, UTF-8 Unicode text
有人可以帮忙吗?
ps:上面的代码对于英文键盘非常有效.
ps:the above code works perfectly fine for English keyboard.
推荐答案
代替使用特定的电报框架,请使用以下代码(仅用于测试目的).
更改chat_id
和BOT_TOKEN
变量.
运行此代码时,如果您的键盘健康,则您的框架会出现utf-8
问题.(代码中的$ telegram所属类)
Instead of using specific telegram framework, use following code (just for test purposes).
Change chat_id
and BOT_TOKEN
variables.
When this code runs, if you receive healthy keyboard then your framework has problem with utf-8
.($telegram belonging class in your code)
<?php
$chat_id = 123; //replace with your client chat id
define('BOT_TOKEN','1234:xyz'); //replace with your token
define('BOTAPI','https://api.telegram.org/bot' . BOT_TOKEN .'/');
$reply_markup = [
'keyboard' => [[['text' => 'سلام'], ['text' => 'خدانگهدار']]],
'resize_keyboard' => true,
'one_time_keyboard' => true,
];
$data = [
'chat_id' => $chat_id,
'text' => 'utf-8 test',
'reply_markup' => json_encode($reply_markup),
];
$ch = curl_init(BOTAPI . 'sendMessage');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
这篇关于电报键盘不显示非英语字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!