emreuyguc/easytag
Composer 安装命令:
composer require emreuyguc/easytag
包简介
Simple html Tag creator.
README 文档
README
Html/Xml markup Tag Creator for Php.
It is an easy markup tag creation tool with PHP. You can use helper methods with the Tag object and build it whenever you want. If you wish, you can have your tag build instantly by using the TagBuild extended class.
For self closing elements in html tags, I defined self closing tags in an extended HtmlTag class and provided instant rendering with the use of TagBuilder.
Usage
Tag Object
- Init
$tag = new Tag(string $name);
- Fast Init
Tag::@tagname(array|string|Tag $element) : Tag
- Element Methods
$tag->setElements(array<Tag|String> $elements);
$tag->appendElement(Tag|String $elements);
$tag->prependElement(Tag|String $elements);
- Attribute Methods
$tag->setAttrs(array<[key,value]> $attrs);
$tag->addAttr(string $attr, string $value);
$tag->removeAttr(string $attr);
- Build methods
$tag->setSelfClosing(bool $isPaired = TRUE);
$tag->build(): string
$tag->render(): void
Fast Tag Builder
TagBuild::@tagname(array|string|Tag $element) : string
Html Tag Builder
HtmlTag::@tagname(array|string|Tag $element) : string
or with attributes
HtmlTag::@tagname(array $attrs, array|string|Tag $element) : string
Features
- All methods can be chained.
- Tag Object have static method for fast tag init. Just call static method with your tag name. return type Tag
- HtmlTag and TagBuild are abstract class and just call static method with your tag name. Elements builds at runtime and only string returns.
- Tag Object and TagBuild fast init feature can take array ,string and tag objects. If you don't like using arrays, you can add infinite parameters of tag or string type and the class defines these parameters as elements.
- When using Tag Object fast init or using TagBuild, if the first parameter is array[key=> value] the class will automatically define attributes.
- In version 1.0.0, all outputs go through the beautify process. This feature currently does not have any settings.
Examples
Object Example
$data = [ [ 'price' => '15.95', 'name' => 'Cap', 'code' => 'C1234' ], [ 'price' => '23.95', 'name' => 'Tshirt', 'code' => 'T1534', ] ]; $products = new Tag('products'); $products->addAttr('last-date','17.08.2021'); foreach ($data as $product_detail){ $product = new Tag('product'); foreach ($product_detail as $key => $value){ $product->appendElement((new Tag($key))->appendElement($value)); } $products->appendElement($product); } $products->render();
- Output
<products last-date="17.08.2021"> <product> <price>15.95</price> <name>Cap</name> <code>C1234</code> </product> <product> <price>23.95</price> <name>Tshirt</name> <code>T1534</code> </product> </products>
Fast Render Example
echo TagBuild::config( TagBuild::server('localhost'), TagBuild::port('8080'), TagBuild::db('tagV1'), TagBuild::user('root'), TagBuild::pass('toor'), );
- OUTPUT
<config> <server>localhost</server> <port>8080</port> <db>tagV1</db> <user>root</user> <pass>toor</pass> </config>
Easy Html for self closing tags
echo HtmlTag::html( HtmlTag::head( HtmlTag::title('Html Example'), HtmlTag::meta(['author' => 'emreuyguc']), HtmlTag::link(['rel' => 'stylesheet','href' => 'your.css']), ), HtmlTag::body( HtmlTag::div(['class' => 'content'],'hello',' world'), HtmlTag::script(['src' => 'your.js']) ) );
- OUTPUT
<html> <head> <title>Html Example</title> <meta author="emreuyguc" /> <link rel="stylesheet" href="your.css" /> </head> <body> <div class="content">hello world</div> <script src="your.js"></script> </body> </html>
emreuyguc/easytag 适用场景与选型建议
emreuyguc/easytag 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「html」 「tag」 「HTML Generator」 「tag creator」 「tag generator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 emreuyguc/easytag 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 emreuyguc/easytag 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 emreuyguc/easytag 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Load DOM document safety
The tag extension for the yii framework
Provides support for tag aware cache for Yii1 application
HTML and form generation
Added a method to Laravel response for handling xml response and also converting Eloquent return to XML.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2021-08-16