-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.php
50 lines (41 loc) · 1.21 KB
/
job.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
46
47
48
49
50
<?php
/**
* @author Marine Gasparyan <[email protected]>
* @date 20.04.2020
*/
/**
* @param string $str
*
* @return array
*/
function getYandexData($str = '') {
// EXAMPLE
//$str = 'Пароль: 5361
// Спишется 101,51р.
// Перевод на счет 41001***********';
if (empty($str) || !preg_match('/[\D]/', $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) {
// find amount
if (stripos($row, 'р.') !== false && stripos($row, ',') !== false) {
$response['amount'] = preg_replace('/[\D]/', '', $row);
} else {
$row = preg_replace('/[\D]/', '', $row);
if (strlen($row) === $yandex_length) {
$response['purse'] = $row;
} elseif (strlen($row)) {
$response['code'] = $row;
}
}
}, $messageArray);
if (!count($response)) {
$response['msg'] = 'error parsing';
}
return $response;
}