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