Мне нужно получить код из этого сообщения, используя php
и имя пользователя меняется в зависимости от пользователя
Web login code. Dear username, we received a request from your account to log in on my.telegram.org. This is your login code:
nJB2G5Yb8RsDo not give this code to anyone, even if they say they're from Telegram! This code can be used to delete your Telegram account. We never ask to send it anywhere.
If you didn't request this code by trying to log in on my.telegram.org, simply ignore this message.
<?php
$text = "Web login code. Dear username, we received a request from your account to log in on my.telegram.org. This is your login code: nJB2G5Yb8Rs
Do not give this code to anyone, even if they say they're from Telegram! This code can be used to delete your Telegram account. We never ask to send it anywhere.
If you didn't request this code by trying to log in on my.telegram.org, simply ignore this message.";
preg_match('~Dear ([^,]+),.* login code: (\S+)\s~isU', $text, $output);
list($dummy, $username, $loginCode) = $output;
echo 'Username: '.$username.' Login Code: '.$loginCode;
?>
Привет @Destroyer, Если проблема заключается только в новой строке, вы можете использовать \s
. Это джокер для новой строки, пробела и табуляции. Вы можете использовать это так: '~Dear ([^,]+),.* login code:\s*(\S+)\s~isU'
Если это не решит вашу проблему, вы должны загрузить свой файл «user/msg.txt» куда-нибудь и дать ссылку
Сначала проблема заключалась в том, что код был в новой строке, поэтому я добавил
\r\n
preg_match('~Dear ([^,]+),.* login code:\r\n(\S+)\s~isU', $text, $output);
, и он будет работать, но когда я использую$msg = file_get_contents("user/msg.txt");
preg_match('~Dear ([^,]+),.* login code:\r\n(\S+)\s~isU', $msg, $output);
, я получаю уведомление: Неопределенное смещение: 2 в E:\xampp\htdocs\index.php в строке 4 Примечание: Неопределенное смещение: 1 в E:\xampp\htdocs\index.php в строке 4 Примечание: Неопределенное смещение: 0 в E:\xampp\htdocs\index.php в строке 4