hexmakina/marker

Marker 是一个 HTML 生成器

安装: 194

依赖: 1

建议: 0

安全: 0

星星: 2

关注者: 1

分支: 0

开放问题: 8

类型:package

0.3.0 2024-05-18 17:41 UTC

This package is auto-updated.

Last update: 2024-09-18 19:29:30 UTC


README

Scrutinizer Code Quality Maintainability PSR-4 Compliant PSR-12 Compliant PHP 7.4 Required Latest Stable Version License

Marker

HTML 生成类向 Christian François Bouche-Villeneuve(又名 Chris Marker)致敬

类 Element

Element 类提供了一个简单且实用的实现,用于使用 PHP 创建和生成有效的 HTML 元素。Element 类的 __toString() 方法根据元素的标签、属性和内容生成 HTML 代码

此外,Element 类还提供了静态简写语法,使用 __callStatic() 与要创建的 HTML 元素名称匹配

第一个参数是内容,第二个是属性

$abbr = Element::abbr('RTFM', ['title' => 'read the file manual']); $p = Element:p('You reading this means you know about '.$abbr); echo $p; //

你阅读这篇意味着你知道 RTFM

::span('inner text', ['class' => 'd-block']) ::p('lorem ipsum') ::img(null, ['src' => 'path/to/jpeg.png', alt='hyper descriptive', 'width' => 100, 'height'=>100]) ::a('click here', ['href' => 'url/to/destination', 'class' => 'nav-link']) ::a('anchor title', ['name' => 'anchor_name'])

关于属性数组,键代表属性名,值代表属性值。如果属性键是整数,则相应的属性名和值被视为布尔属性。

示例用法

$element = new Element('section', 'Hello World!', [
    'id' => 'publication',
    'class' => 'container',
    'data-toggle' => 'modal',
    'data-target' => '#myModal',
]);

<section id="publication" class="container" data-toggle="modal" "data-target"="#myModal">Hello World!</section>

或者,使用空元素和布尔属性

$element = new Element('input', null, [ 'type' => 'checkbox', 'checked', 'disabled', 'class' => 'checkbutton' ]);

类 Marker

类 Form