krzysztofzylka / html-generator
HTML生成器
2.0.6
2024-02-04 09:35 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^10
README
PHP中的HTML生成器
用法
静态创建标签
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag('div')
或
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag( 'div', 'content' )
或
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag( 'div', 'content', 'classes' )
或
echo \Krzysztofzylka\HtmlGenerator\HtmlGenerator::createTag( 'div', 'content', 'classes', ['attributes' => 'value'] )
创建标签
echo new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div');
方法
设置内容
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->setContent('content')
获取内容
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->getContent()
追加内容
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->appendContent('append content')
添加属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->addAttributes(['id' => 'div-id', 'class' => 'classes'])
添加属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->addAttribute('id', 'div-id')
获取属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->getAttribute('id')
将字符串追加到属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->appendAttribute('class', 'next_class')
移除属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->removeAttribute('class')
添加id属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->setId('div-id')
添加name属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('input')) ->setName('input-name')
添加class属性
echo (new \Krzysztofzylka\HtmlGenerator\HtmlGenerator('div')) ->setClass('class')