BTTM

BTTM\HTML

Apr 30th, 2021 (edited)
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2.     /*
  3.         - A simple HTML Rendering system.
  4.         - Easy create static HTML Pages!
  5.     */
  6.  
  7.  
  8.     namespace BTTM;
  9.  
  10.     class HTML {
  11.         public $type;
  12.         public $content;
  13.         public $head;
  14.         public $page;
  15.        
  16.         function __constuct() {
  17.             $this->type = 'html';
  18.             $this->pageContent = '';
  19.         }
  20.         private function head($txt) {
  21.             $this->head .= $txt;
  22.         }
  23.         function title($t = 'My site') {
  24.             $this->head('<title>'.$t.'</title>');
  25.         }
  26.         function link($link = 'index.php', $text = null) {
  27.             if ($text != null) {
  28.                 return '<a href="'.$link.'">'.$text.'</a>';
  29.             } else {
  30.                 return '<a href="'.$link.'">'.$link.'</a>';
  31.             }
  32.         }
  33.         function addElement($type = 'div', $text = 'DIV CONTENT', $att = null) {
  34.             $at = '';
  35.             if ($att != null) {
  36.                 $at .= ' ';
  37.                 foreach ($att as $a => $v) {
  38.                     $at .= $a . '="' . $v . '" ';
  39.                 }
  40.             }
  41.             if (is_array($text)) {
  42.                 $text = join($text, '');
  43.             }
  44.             $this->pageContent .= '<'.$type.''.$at.'>'.$text.'</'.$type.'>';
  45.         }
  46.         function render() {
  47.                 $this->content = '<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0">';
  48.            
  49.                 $style = '';
  50.                 $style .= 'body {font-family:sans-serif;} a{color:blue;text-decoration:underline;font-weight: bold;}';
  51.            
  52.                 $this->head('<style>'.$style.'</style>');
  53.                 $this->content .= $this->head;
  54.                 $this->content .= '</head><body>';
  55.                
  56.                 $this->content .= $this->pageContent;
  57.            
  58.                 $this->content .= '</body>';
  59.            
  60.                 echo $this->content;
  61.             }
  62.     }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment