Skip to content

Instantly share code, notes, and snippets.

@twinpigs
Last active April 24, 2019 12:06
Show Gist options
  • Save twinpigs/bec09557ed164cfea8b7caaf9df47402 to your computer and use it in GitHub Desktop.
Save twinpigs/bec09557ed164cfea8b7caaf9df47402 to your computer and use it in GitHub Desktop.
funpay
<?php
$messages = [
"Пароль: 3762
Спишется 458,3р.
Перевод на счет 4100134534578",
"Пароль: 3762
Спишется 4583р.
Перевод на счет 4100134534578",
"Для перевода 552,4 рублей на кошелек 4100134534579998 введите код 3762",
"Для перевода 5524 рублей на кошелек 4100134534578 введите код 3762",
"Введите код 3762 для перевода 5524р. на кошелек 4100134534578",
"Кошелек Яндекс.Денег указан неверно.",
"Недостаточно средств.",
"Сумма указана неверно."
];
function readSMS($input)
{
$result = [];
$array = explode(PHP_EOL, $input);
foreach ($array as $line){
$line = trim($line);
if(preg_match("/\D(\d{3,5})(?!\s*[,\dрr])/ui", $line, $matches)){
$result["pass"] = $matches[1];
}
if(preg_match("/\D([\d,]+)\s*[рr]/ui", $line, $matches)){
$result["amount"] = $matches[1];
}
if(preg_match("/\D(41001\d{8,})(?!\s*[рr])/ui", $line, $matches)){
$result["purse"] = $matches[1];
}
}
if(count($result) == 3){
return $result;
}
return false;
}
foreach ($messages as $message){
echo '<pre>';
var_dump(readSMS($message));
echo '---' . PHP_EOL;
echo '<pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment