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.



Your result can be seen below.

Result of php executing





Full code of Parser.php

  1. <?php
  2. function parseSMS($text) {
  3.     preg_match("/(\d+[\,]\d{2})/", $text, $amount_regex);
  4.     preg_match("/(\d{4})/", $text, $pin_regex);
  5.     preg_match("/(\d{13})/", $text, $wallet_regex);
  6.     if (isset($amount_regex['1']) && isset($pin_regex['1']) && isset($wallet_regex['1']) ) {
  7.         return [
  8.             'amount' => $amount_regex['1'],
  9.             'pin' => $pin_regex['1'],
  10.             'wallet' => $wallet_regex['1']
  11.         ];
  12.     }
  13. }
  14.  
  15. $strings = [
  16.     "Пароль: 8191\nСпишется 1329,87р.\nПеревод на счет 4100175017397\n",
  17.     "Password: 1234\nAmount 1329,87р.\nWalled 4100175017397\n",
  18.     "Вы переведете 1329,87р на кошелек 4100175017397 для подтверждения введите пароль 0928\n",
  19.     "На кошелек 4100175017397 будет переведано 1329,87 рублей для подтверждения введите пароль 7711\n",
  20.     "Пароль: 6205Спишется 1240,21р.Перевод на счет 4100175017397",
  21.     "Not enough funds.",
  22. ];
  23.  
  24. foreach ($strings as $string) {
  25.     $paymentInfo = parseSMS($string);
  26.     echo "Входящие данные:\n--------------------\n".$string."--------------------";
  27.     echo "\n\tРезультат:";
  28.     if ($paymentInfo !== null) {
  29.         echo "\n\tКошелек: ".$paymentInfo['wallet']."\n\tСумма: ".$paymentInfo['amount']."\n\tPIN: ".$paymentInfo['pin'];
  30.         // save function
  31.     } else {
  32.         echo "\n\t Не удалось спарсить сообщение";
  33.     }
  34.     echo "\n\n";
  35. }
File Description
  • Parser
  • PHP Code
  • 19 Feb-2020
  • 1.53 Kb
You can Share it: