Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. function getData($str)
  2. {
  3.     $number_reg = "/\d{11,16}\D?/";
  4.     $amount_reg = "/(\d+[,.]\d{1,2}|\d{1,6})\s?[^0-9\s]{1,7}\s[\n]?/";
  5.     $code_reg = "/\d{4,10}\s{0,2}/";
  6.  
  7.     $output = [];
  8.     $result = [];
  9.     preg_match($amount_reg, $str, $result);
  10.     $output['amount'] = (double)str_replace(',', '.', preg_replace('/[^0-9,.]/', '', $result[1]));
  11.     preg_match($number_reg, $str, $result);
  12.     $output['num'] = ((int)$result[0]);
  13.     preg_match($code_reg, $str, $result);
  14.     $output['code'] = ((int)$result[0]);
  15.     var_dump($output);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement