krzysztofzylka/html-generator

2.0.6 2024-02-04 09:35 UTC

This package is auto-updated.

Last update: 2024-09-04 11:14:20 UTC


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')