krzysztofzylka / html-generator
HTML generator
2.0.6
2024-02-04 09:35 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^10
README
Html generator in PHP
Usage
Static create tag
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag('div')
or
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag( 'div', 'content' )
or
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag( 'div', 'content', 'classes' )
or
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag( 'div', 'content', 'classes', ['attributes' => 'value'] )
Create tag
echo new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div');
Methods
Set content
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->setContent('content')
Get content
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->getContent()
Append content
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->appendContent('append content')
Add attributes
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->addAttributes(['id' => 'div-id', 'class' => 'classes'])
Add attribute
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->addAttribute('id', 'div-id')
Get attribute
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->getAttribute('id')
Append string to attribute
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->appendAttribute('class', 'next_class')
Remove attribute
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->removeAttribute('class')
Add id attribute
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->setId('div-id')
Add name attribute
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('input')) ->setName('input-name')
Add class attribute
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->setClass('class')