Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function parseSms(string $sms): array
- {
- $accountPattern = '(41001\d{8,11})';
- $sumPattern = '(\d+(?:[,.]\d+)?)р';
- $codePattern = '(\d+)';
- $countMatches = preg_match_all("/$accountPattern|$sumPattern|$codePattern/", $sms, $matches, PREG_SET_ORDER);
- if ($countMatches === false)
- throw new Error('Ошибка при попытке разбора СМС', preg_last_error());
- elseif ($countMatches === 0)
- throw new Error('Не удалось получить никаких данных из СМС');
- $code = $sum = $account = null;
- foreach ($matches as $match) {
- if ($match[1])
- $account = $match[1];
- elseif ($match[2])
- $sum = $match[2];
- elseif ($match[3])
- $code = $match[3];
- }
- return compact('code', 'sum', 'account');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement