Advertisement
VZhelev

Untitled

May 29th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2. $input = fgets(STDIN);
  3. $input = str_replace(",", "", $input);
  4. $input = str_replace(".", "", $input);
  5. $input = str_replace("-", " ", $input);
  6. $input = str_replace(":", " ", $input);
  7.  
  8. $suffix = strtok($input, "|");
  9. $text = strtok("|");
  10.  
  11. $result = strtok($text, " ");
  12. $i = 0;
  13.  
  14. $textArray[0] = false;
  15.  
  16. while($result !== false)
  17. {
  18.    
  19.     if(preg_match("/$suffix\z/", $result))
  20.     {
  21.         $textArray[$i] = $result;
  22.         $i++;
  23.     }
  24.    
  25.     $result = strtok(" ");
  26. }
  27.  
  28. if($textArray[0] != false)
  29. {
  30.     sort($textArray);
  31.     echo "<ul>";
  32.     foreach($textArray as $value)
  33.     {
  34.         echo "<li>" . $value . "</li>";
  35.     }
  36.     echo "</ul>";
  37. }
  38. else
  39. {
  40.   echo "<ul></ul>";
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement