input = $name; $this->read(); } else { $this->name = $name; $this->comment = $comment; $this->email = $email; } } public function display() { $text = []; if ($this->name) { $text[] = $this->name; } if ($this->comment) { $text[] = "({$this->comment})"; } if ($this->email) { $text[] = "<{$this->email}>"; } return implode(' ', $text); } function body() { return ''.$this->display(); // Convert to string is the body } function read() { $this->data = $this->input; // User IDs of the form: "name (comment) " if (preg_match('/^([^\(]+)\(([^\)]+)\)\s+<([^>]+)>$/', $this->data, $matches)) { $this->name = trim($matches[1]); $this->comment = trim($matches[2]); $this->email = trim($matches[3]); } // User IDs of the form: "name " else if (preg_match('/^([^<]+)\s+<([^>]+)>$/', $this->data, $matches)) { $this->name = trim($matches[1]); $this->comment = NULL; $this->email = trim($matches[2]); } // User IDs of the form: "name" else if (preg_match('/^([^<]+)$/', $this->data, $matches)) { $this->name = trim($matches[1]); $this->comment = NULL; $this->email = NULL; } // User IDs of the form: "" else if (preg_match('/^<([^>]+)>$/', $this->data, $matches)) { $this->name = NULL; $this->comment = NULL; $this->email = trim($matches[2]); } } }