我有一个像[This]这样的raw
它造成了混乱,所以我决定自己创建。我能写的代码-
<?php
if (preg_match_all('/btestb/', $message)) {
$sendmes = "https://api.telegram.org/bot".$botToken."/sendMessage?chat_id=".$chatId."&text=<code>Wait...</code>&reply_to_message_id=".$message_id."&parse_mode=HTML";
$sent = json_decode(file_get_contents($sendmes) ,1);
$mes_id = $sent['result']['message_id'];
$cclist = preg_replace("/[^0-9|n]/", "",$message);
$array = explode("n", $cclist);
foreach ($array as $res) {
editMessage($chatId,"CHECKING CC : $res",$mes_id);
$cc = file_get_contents('https://oneclass.junaidrahman2.repl.co/***.php?lista='.$res.'');
$msg = trim(strip_tags(getStr($cc,' <br>Result:','</span><br>')));
$i = "CC : $res%0AResult : $msg";
editMessage($chatId,"$i",$mes_id);
}
}
它将每次编辑消息。我需要保存前一个循环的结果。如:
CC : 72611111
Result : Abc
CC : 625262
Result : jsh
我不知道我该怎么做。请帮助
你应该这样组织你的foreach:
if (preg_match_all('/btestb/', $message)) {
$sendmes = "https://api.telegram.org/bot".$botToken."/sendMessage?chat_id=".$chatId."&text=<code>Wait...</code>&reply_to_message_id=".$message_id."&parse_mode=HTML";
$sent = json_decode(file_get_contents($sendmes) ,1);
$mes_id = $sent['result']['message_id'];
$cclist = preg_replace("/[^0-9|n]/", "",$message);
$array = explode("n", $cclist);
//Initialize an empty array here to collect the item in the loop
$new_array = [];
foreach ($array as $res) {
editMessage($chatId,"CHECKING CC : $res",$mes_id);
$cc = file_get_contents('https://oneclass.junaidrahman2.repl.co/***.php?lista='.$res.'');
$msg = trim(strip_tags(getStr($cc,' <br>Result:','</span><br>')));
$i = "CC : $res%0AResult : $msg";
editMessage($chatId,"$i",$mes_id);
// Then inside your foreach your item get pushed into the array
//on each iteration like so:
$new_array[] = $i
}
}
你可以看到$new_array在foreach循环后的值,打印如下:
print_r($new_array);