phpist

Untitled

Oct 26th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php ## Базовый класс страницы
  2. class Page
  3. {
  4. // Любая страница имеет заголовок
  5. protected $title;
  6. // И содержимое
  7. protected $content;
  8. // Конструктор класса
  9. public function __construct($title = '', $content = '')
  10. {
  11. $this->title = $title;
  12. $this->content = $content;
  13. }
  14. // Получение заголовка страницы
  15. public function title()
  16. {
  17. return $this->title;
  18. }
  19. // Получение содержимого страницы
  20. public function content()
  21. {
  22. return $this->content;
  23. }
  24. // Формирование HTML-представления страницы
  25. public function render()
  26. {
  27. echo "<h1>".htmlspecialchars($this->title())."</h1>";
  28. echo "</p>".nl2br(htmlspecialchars($this->content()))."</p>";
  29. }
  30. }
  31. $aa = new Page();
  32. $title = "Hello world!";
  33.  
  34. $content = "Hello world!";
  35. echo $aa->content($content);
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment