-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobV2.php
45 lines (38 loc) · 1.15 KB
/
jobV2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* @author Marine Gasparyan <[email protected]>
* @date 20.04.2020
*/
/**
* @param string $str
*
* @return array
*/
function getYandexData($str = '') {
if (empty($str) || !preg_match('/[^0-9]/', $str))
return false;
// get each row data
$messageArray = explode("\n", $str);
// make result
$response = [];
// yandex purse length (КОШЕЛЕК), it has constant length
$yandex_length = 16;
array_map(function($row) use(&$response, $yandex_length) {
$number = filter_var($row, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND);
// get amount
if (stripos($number, ',') !== false) {
$response['amount'] = preg_replace('/[^0-9,]/', '', $number);
} else {
// get purse
if (strlen($number) === $yandex_length) {
$response['purse'] = $number;
} elseif (strlen($number)) {
$response['code'] = $number;
}
}
}, $messageArray);
if (!count($response)) {
$response['msg'] = 'error parsing';
}
return $response;
}