Skip to content

Instantly share code, notes, and snippets.

@kovalevcon
Created August 13, 2019 18:58
Show Gist options
  • Save kovalevcon/5014bc44b4715218484287cc3394b779 to your computer and use it in GitHub Desktop.
Save kovalevcon/5014bc44b4715218484287cc3394b779 to your computer and use it in GitHub Desktop.
https://funpay.ru/job.html - тестовое задание
<?php
/**
* Parse yandex SMS
*
* @param string $msg
* @return array
*/
function parseYandexSMS(string $msg): array
{
$yandexCodeRegex =
'/^[\W?:\040?]+\s*(?<code>\d{4})[\W?\040?]+\s*(?<amount>\d+,\d+)[\W?\040?]+\s*(?<yandex_account>\d{15})$/';
return preg_match($yandexCodeRegex, $msg, $matches) ? [
'code' => $matches['code'],
'amount' => $matches['amount'],
'yandex_account' => $matches['yandex_account'],
] : [];
}
$message = 'Пароль: 3131
Спишется 1005,03р.
Перевод на счет 410013408143344';
$result = parseYandexSMS($message);
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment