Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. if (!function_exists('parseSMS')) {
  2.     function parseSMS(string $sms): ?array
  3.     {
  4.         preg_match('/\b\d{4}(?!,\d{2})\b/m', $sms, $password);
  5.  
  6.         if (!isset($password[0])) {
  7.             return null;
  8.         }
  9.  
  10.         preg_match('/\d{1,}(,|\.)\d{2}/m', $sms, $amount);
  11.  
  12.         if (!isset($amount[0])) {
  13.             return null;
  14.         }
  15.  
  16.         preg_match('/\d{13,16}/m', $sms, $wallet);
  17.  
  18.         if (!isset($wallet[0])) {
  19.             return null;
  20.         }
  21.  
  22.         return [
  23.             'password' => $password[0],
  24.             'amount' => (float)str_replace(',', '.', $amount[0]),
  25.             'wallet' => $wallet[0],
  26.         ];
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement