Advertisement
plezzz

Arriving in Kathmandu

Apr 15th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. $patternName = '/(?<name>[a-zA-Z0-9]+)([!@#$?]+)/';
  4. $pattern = '/^(?<name>[a-zA-Z0-9!@#$?]+)(=(?<length>[0-9]+))(<<(?<geocode>.*))/m';
  5. $arr = [];
  6. while (true) {
  7.     $input = readline();
  8.     if ($input === 'Last note') {
  9.         break;
  10.     }
  11.  
  12.     if (preg_match($pattern, $input)) {
  13.         preg_match_all($pattern, $input, $matchesLG, PREG_SET_ORDER, 0);
  14.  
  15.         $length = $matchesLG[0]["length"];
  16.         $geocode = $matchesLG[0]["geocode"];
  17.         $longName = $matchesLG[0]["name"];
  18.  
  19.         $name = "";
  20.         preg_match_all($patternName, $longName, $matchesName, PREG_SET_ORDER, 0);
  21.         foreach ($matchesName as $nameParts) {
  22.             $name .= $nameParts["name"];
  23.         }
  24.  
  25.         if (strlen($geocode) == $length) {
  26.             echo "Coordinates found! $name -> $geocode\n";
  27.         } else {
  28.             echo "Nothing found!\n";
  29.         }
  30.  
  31.     } else {
  32.         echo "Nothing found!\n";
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement