jjgrainger / html
使用PHP对象生成HTML标记
v0.1.0
2022-05-18 16:58 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: 8.*
- squizlabs/php_codesniffer: 3.*
README
使用PHP对象生成HTML标记
要求
- PHP >= 7.2
- Composer
安装
$ composer require jjgrainger/html
用法
Element
类可以用来生成任何类型的HTML标记。
use HTML\Element; // Creat a link element. $link = new Element('a'); // Set the href attribute. $link->setAttribute('href', 'https://google.com'); // Set the class attribute. $link->setAttribute('class', 'text-link'); // Append attribute values, in this case adding a 'active' class to the element. $link->appendAttribute('class', 'active'); // Set the content for the $link->setContent('Hello World!'); // Outputs HTML echo $link;
以上将输出以下内容。
<a href="https://google.com" class="text-link active">Hellow World!</a>
注意
作者
Joe Grainger