timostamm/html-builder
Composer 安装命令:
composer require timostamm/html-builder
包简介
Tiny PHP HTML Builder Library
README 文档
README
A simple library to generate HTML fragments with a jquery-like interface.
This library does not parse HTML, and it does not provide element lookup via selectors or otherwise. It is focused on building simple HTML fragments, for example embed codes, while taking care of proper escaping and other simple syntax rules. Its purpose is to replace manual concatenation of strings.
Examples
function generateBarcodeHtml( $barcode ) { $generator = new BarcodeGeneratorHTML(); $htmlCode = $generator->getBarcode( $$barcode->toString(), $$barcode->getType(), 1, 45 ); $el = Html::element('div'); $el->addClass('barcode-container'); Html::element('div') ->addClass('barcode-bars') ->html( $htmlCode ) ->appendTo($el); Html::element('div') ->addClass('barcode-number') ->text( $normalizedValue->toString() ) ->appendTo($el); return $el; } public function generateMenu(array $items) { $ul = Html::element('ul'); foreach ( $this->items as $item ) { $li = Html::element('li') ->appendTo( $ul ) ->toggleClass('active', $item['id'] === $this->activeId); Html::element('a') ->attr('href', '/' . $item['url_key'] . '.html') ->text( $item['title'] ) ->appendTo( $li ); } return (string)$ul; }
Factory methods
Html::element($tagName)
Creates an element.
Html::comment($text)
Creates a comment node.
Html::text($text)
Creates a text node.
Appending elements
$el->append($tagNameOrNode)
Add the new element as the last child.
$el->appendTo(Element $target)
Add the element as the targets last child.
$el->prepend($tagNameOrNode)
Add the new element as the first child.
$el->prependTo($Element $target)
Add the element as the targets first child.
Element Attributes
$el->attr($name, $value)
Sets the attribute with the given name and value.
$el->attr($name)
Returns the attribute with the given name.
$el->attr()
Returns all attributes as an associative array.
$el->removeAttr($name)
Removes the attribute with the given name.
Element html
$el->html($str)
Adds a raw html string as a child.
$el->html()
Returns the html representation of the content.
$el->__toString() / $el->toString()
Returns the node as html.
Element text
$el->html($str)
Adds a text node.
$el->text()
Returns the text contents of this node including its descendants.
Element classes
$el->addClass($class)
Add one or more classes. Multiple classes are separated by a space.
$el->hasClass($class)
Returns true if the element has the class.
$el->toggleClass($class, $state)
Remove or add the class.
get classes
Use $el->attr("class")
Element tag name
$el->getTagname()
Returns the tag name.
$el->switchTagname($value)
Changes the tag name.
timostamm/html-builder 适用场景与选型建议
timostamm/html-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.86k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 10 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 timostamm/html-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 timostamm/html-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0
- 更新时间: 2017-10-04