Parser - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Parser.php
- <?php
- function parseSMS($text) {
- preg_match("/(\d+[\,]\d{2})/", $text, $amount_regex);
- preg_match("/(\d{4})/", $text, $pin_regex);
- preg_match("/(\d{13})/", $text, $wallet_regex);
- if (isset($amount_regex['1']) && isset($pin_regex['1']) && isset($wallet_regex['1']) ) {
- return [
- 'amount' => $amount_regex['1'],
- 'pin' => $pin_regex['1'],
- 'wallet' => $wallet_regex['1']
- ];
- }
- }
- $strings = [
- "Пароль: 8191\nСпишется 1329,87р.\nПеревод на счет 4100175017397\n",
- "Password: 1234\nAmount 1329,87р.\nWalled 4100175017397\n",
- "Вы переведете 1329,87р на кошелек 4100175017397 для подтверждения введите пароль 0928\n",
- "На кошелек 4100175017397 будет переведано 1329,87 рублей для подтверждения введите пароль 7711\n",
- "Пароль: 6205Спишется 1240,21р.Перевод на счет 4100175017397",
- "Not enough funds.",
- ];
- foreach ($strings as $string) {
- $paymentInfo = parseSMS($string);
- echo "Входящие данные:\n--------------------\n".$string."--------------------";
- echo "\n\tРезультат:";
- if ($paymentInfo !== null) {
- echo "\n\tКошелек: ".$paymentInfo['wallet']."\n\tСумма: ".$paymentInfo['amount']."\n\tPIN: ".$paymentInfo['pin'];
- // save function
- } else {
- echo "\n\t Не удалось спарсить сообщение";
- }
- echo "\n\n";
- }
File Description
- Parser
- PHP Code
- 19 Feb-2020
- 1.53 Kb
You can Share it:
Latest PHP Pastes