Advertisement
killrawr

PhpContentDocument.class.php

Apr 7th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class PhpContentDocument
  5. {
  6.    
  7.     protected $html_content_elements = array();
  8.     protected $content_delimiter = PHP_EOL;
  9.     protected $title_text = NULL;
  10.    
  11.     public function __construct($title, $character_set = 'UTF-8')
  12.     {
  13.         $this->title_text    = $title;
  14.         $this->character_set = $character_set;
  15.     }
  16.    
  17.     protected static function tidyElementKey($element_key)
  18.     {
  19.         $element_key = (string) $element_key;
  20.         $element_key = trim($element_key);
  21.         $element_key = str_replace(' ', '_', $element_key);
  22.         return $element_key;
  23.     }
  24.    
  25.     public function addElement($element_key, $element)
  26.     {
  27.         $element_key                               = self::tidyElementKey($element_key);
  28.         $this->html_content_elements[$element_key] = $element;
  29.     }
  30.    
  31.     public function get_string()
  32.     {
  33.        
  34.         $sample_html_document   = array();
  35.         $sample_html_document[] = "<!DOCTYPE HTML>";
  36.         $sample_html_document[] = "<html>";
  37.         $sample_html_document[] = "<head>";
  38.         $sample_html_document[] = "<title>{$this->title_text}</title>";
  39.         $sample_html_document[] = "<meta http-equiv=\"Content-Type\" content=\"text/html;charset={$this->character_set}\" />";
  40.         $sample_html_document[] = "<body>";
  41.         $sample_html_document[] = implode($this->content_delimiter, $this->html_content_elements);
  42.         $sample_html_document[] = "</body>";
  43.         $sample_html_document[] = "</html>";
  44.        
  45.         $sample_html_document_string = "";
  46.         $sample_html_document_string = implode($this->content_delimiter, $sample_html_document);
  47.        
  48.         return $sample_html_document_string;
  49.        
  50.     }
  51.    
  52. }
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement