Advertisement
fbinnzhivko

Untitled

Jul 3rd, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2. class Person
  3. {
  4.     private $name;
  5.     private $surname;
  6.     private $age;
  7.     private $grade;
  8.     private $date;
  9.     private $town;
  10.     public function __construct(
  11.         string $name,
  12.         string $surname,
  13.         int $age,
  14.         float $grade,
  15.         string $date,
  16.         string $town)
  17.     {
  18.         $this->name = $name;
  19.         $this->surname = $surname;
  20.         $this->age = $age;
  21.         $this->grade = $grade;
  22.         $this->date = $date;
  23.         $this->town = $town;
  24.     }
  25.     public function toJson() : string
  26.     {
  27.         return json_encode(get_object_vars($this), JSON_UNESCAPED_SLASHES);
  28.     }
  29. }
  30. if (isset($_GET['input']) &&
  31.     isset($_GET['delimiter'])
  32. ) {
  33.     $input = $_GET['input'];
  34.     $delimiter = $_GET['delimiter'];
  35.     $objTokens = explode(PHP_EOL, $input);
  36.     $tokens = [];
  37.     foreach ($objTokens as $token) {
  38.         $tokens[] = explode($delimiter, $token)[1];
  39.     }
  40.     $person = new Person(
  41.         $tokens[0],
  42.         $tokens[1],
  43.         intval($tokens[2]),
  44.         floatval($tokens[3]),
  45.         $tokens[4],
  46.         $tokens[5]);
  47.     echo $person->toJson();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement