depage-forms v1.4.1
html forms made easy
Loading...
Searching...
No Matches
Html.php
Go to the documentation of this file.
1<?php
2
10
11namespace Depage\HtmlForm\Elements;
12
13use Depage\HtmlForm\Abstracts\HtmlDom as HtmlSanitizer;
14
37class Html
38{
42 private $htmlString;
46 private $sanitize = true;
50 private $allowedTags = null;
51
58 public function __construct(string $htmlString, $parameters = [])
59 {
60 $this->htmlString = $htmlString;
61
62 if (isset($parameters['sanitize']) && is_bool($parameters['sanitize'])) {
63 $this->sanitize = $parameters['sanitize'];
64 }
65 if (isset($parameters['allowedTags']) && is_array($parameters['allowedTags'])) {
66 $this->allowedTags = $parameters['allowedTags'];
67 }
68 }
69
75 public function __toString(): string
76 {
77 if ($this->sanitize && class_exists(HtmlSanitizer::class)) {
78 $sanitizer = new HtmlSanitizer();
79 $sanitizer->loadHTML($this->htmlString);
80 $sanitizer->cleanHTML($this->allowedTags, null, false);
81 return (string) mb_trim($sanitizer);
82 }
83
84 return (string) $this->htmlString;
85 }
86}
87
88/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Can be used to insert custom HTML between rendered HTML elements.
Definition Html.php:38
__construct(string $htmlString, $parameters=[])
html class constructor
Definition Html.php:58
__toString()
Renders element to sanitized HTML.
Definition Html.php:75