Advertisement
Venciity

Concerts

Aug 26th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Concerts</title>
  6. </head>
  7. <body>
  8.     <form action="" method="post">
  9.         <input type="text" name="inputText"/>
  10.         <input type="submit"/>
  11.     </form>
  12.     <?php
  13.         if (isset($_POST['inputText'])) {
  14.             $inputText = $_POST['inputText'];
  15.             $strings = preg_split("/Stadium/" , $inputText , -1 , PREG_SPLIT_NO_EMPTY);
  16.             //var_dump($strings);
  17.  
  18.             $concertInfo = [];
  19.  
  20.             for ($i = 0; $i < count($strings); $i++) {
  21.                 $currentStringWords = explode(" | ", $strings[$i]);
  22.                 $band = $currentStringWords[0];
  23.                 $town = $currentStringWords[1];
  24.                 $date = $currentStringWords[2];
  25.                 $stadium = $currentStringWords[3] . "stadium";
  26.  
  27.                 for ($j = 0; $j < count($currentStringWords); $j++) {
  28.                     if (isset($concertInfo[$town])) {
  29.                         if (isset($concertInfo[$town][$stadium])) {
  30.                             if (in_array($band, $concertInfo[$town][$stadium])) {
  31.                                 continue;
  32.                             }
  33.                             else {
  34.                                 array_push($concertInfo[$town][$stadium], $band);
  35.                             }
  36.                         }
  37.                         else {
  38.                             $concertInfo[$town][$stadium] = [];
  39.                             array_push($concertInfo[$town][$stadium], $band);
  40.                         }
  41.                     }
  42.                     else {
  43.                         $concertInfo[$town] = [];
  44.                         $concertInfo[$town][$stadium] = [];
  45.                         array_push($concertInfo[$town][$stadium], $band);
  46.                     }
  47.                 }
  48.             }
  49.             // sort all arrays
  50.             ksort($concertInfo);
  51.             foreach ($concertInfo as $key => $value) {
  52.                 ksort($concertInfo[$key]);
  53.                 foreach ($concertInfo[$key] as $inner => $value) {
  54.                     sort($concertInfo[$key][$inner]);
  55.                 }
  56.  
  57.             }
  58.             echo json_encode($concertInfo);
  59.         }
  60.     ?>
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement