0

I need to get the code from this msg using php

and username changes according to user

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.

Skora
  • 107
  • 11

1 Answers1

1

<?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;

?>

Onur Uslu
  • 1,044
  • 1
  • 7
  • 11
  • At first, the problem was that the code was in a new line So I added `\r\n` `preg_match('~Dear ([^,]+),.* login code:\r\n(\S+)\s~isU', $text, $output);` and its work will but when i use `$msg = file_get_contents("user/msg.txt");` `preg_match('~Dear ([^,]+),.* login code:\r\n(\S+)\s~isU', $msg, $output);` i get Notice: Undefined offset: 2 in E:\xampp\htdocs\index.php on line 4 Notice: Undefined offset: 1 in E:\xampp\htdocs\index.php on line 4 Notice: Undefined offset: 0 in E:\xampp\htdocs\index.php on line 4 – Skora Mar 10 '19 at 15:25
  • 1
    Hi @Destroyer , If the problem is just a new line, you can use `\s`. It is joker for new line, space and tab. You can use it like this: `'~Dear ([^,]+),.* login code:\s*(\S+)\s~isU'` If it doesn't solve your problem, you should upload your "user/msg.txt" file to somewhere and give a link – Onur Uslu Mar 10 '19 at 16:00