Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PhpContentDocument
- {
- protected $html_content_elements = array();
- protected $content_delimiter = PHP_EOL;
- protected $title_text = NULL;
- public function __construct($title, $character_set = 'UTF-8')
- {
- $this->title_text = $title;
- $this->character_set = $character_set;
- }
- protected static function tidyElementKey($element_key)
- {
- $element_key = (string) $element_key;
- $element_key = trim($element_key);
- $element_key = str_replace(' ', '_', $element_key);
- return $element_key;
- }
- public function addElement($element_key, $element)
- {
- $element_key = self::tidyElementKey($element_key);
- $this->html_content_elements[$element_key] = $element;
- }
- public function get_string()
- {
- $sample_html_document = array();
- $sample_html_document[] = "<!DOCTYPE HTML>";
- $sample_html_document[] = "<html>";
- $sample_html_document[] = "<head>";
- $sample_html_document[] = "<title>{$this->title_text}</title>";
- $sample_html_document[] = "<meta http-equiv=\"Content-Type\" content=\"text/html;charset={$this->character_set}\" />";
- $sample_html_document[] = "<body>";
- $sample_html_document[] = implode($this->content_delimiter, $this->html_content_elements);
- $sample_html_document[] = "</body>";
- $sample_html_document[] = "</html>";
- $sample_html_document_string = "";
- $sample_html_document_string = implode($this->content_delimiter, $sample_html_document);
- return $sample_html_document_string;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement