Answer the question
In order to leave comments, you need to log in
How to divide the text of a variable into several parts by cutting off on a certain word?
Hello. Telegram has a limit on the number of characters in a message: 4096. The situation that I am trying to prevent is unlikely, but possible. I need, in case of exceeding the message size limit, divide it into several pieces and send it. But there is a moment: my message looks like this:
$output = "<i>Запись №513</i> \nКакой-то текст на 50-150 символов\n".hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0').hex2bin('E380B0')."\n<i>Запись №514</i>\nA Какой-то текст на 50-150 символов";
function telega($method, $data) {
$ch = curl_init("https://api.telegram.org/bot00000:00000000/$method");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$curlRes1 = curl_exec($ch);
echo $curlRes1;
}
$data = [
"chat_id"=> $main_id,
"text"=> $output,
"parse_mode" => "html"
];
//Отправляем сообщение
telega("sendMessage", $data);
<i>Запись
and send it already in 2 stages? That is, this is exactly the word with which the next infa begins.
Answer the question
In order to leave comments, you need to log in
Well.... What is a string? it's almost an array, that is... we take strlen and check the length if it is greater than 4096, but insert a separator into the string at this place, for example "_-_" and divide the string by characters as many times as the array exceeds 4096
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question