Advertisement
Guest User

test

a guest
Feb 20th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. <?php
  2.  
  3. $re = '/((\s|^)(?<code>\d{4})(\t|\s|$))|(?<yandex>\d{14})|((?<money>\d{1,}(\,\d{2}|\.\d{2})?)р\.)/m';
  4. $str = '
  5. Пароль: 2918
  6. Перевод на счет 41001439721971
  7. Спишется 235,74р.';
  8.  
  9. preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
  10. $result = [];
  11.  
  12. foreach($matches as $match){
  13.     $resource = ['code','yandex','money'];
  14.     foreach($resource as $res){
  15.          if(isset($match[$res]) && trim($match[$res]) != "") {
  16.             $result[$res] = trim($match[$res]);
  17.          }
  18.     }
  19.    
  20. }
  21.  
  22. var_dump($result);
  23.  
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement