flsouto/htattrs
Composer 安装命令:
composer require flsouto/htattrs
包简介
Build html attributes through the ArrayObject API
关键字:
README 文档
README
This package can be used to build html tag attributes through a simple, array-based API.
Installation
Use composer:
composer require flsouto/htattrs
Usage
Building html attributes:
<?php
require_once('vendor/autoload.php');
$attrs = new FlSouto\HtAttrs();
$attrs['name'] = 'test';
$attrs['onclick'] = 'alert("Test!")';
echo "<a $attrs>Click me</a>";
The above code will produce:
<a name="test" onclick="alert("Test!")">Click me</a>
Since the HtAttrs class extends php's native \ArrayObject, you could initialize it with an array:
<?php
require_once('vendor/autoload.php');
$attrs = new FlSouto\HtAttrs([
'name' => 'test',
'onclick' => 'alert("Test!")'
]);
echo "<a $attrs>Click me</a>";
The above code will produce:
<a name="test" onclick="alert("Test!")">Click me</a>
The Especial Style Attribute
The style attribute is always an instance of the FlSouto\HtAttrStyle class, which in turn produces a list of inline css properties when outputted:
<?php
require_once('vendor/autoload.php');
$attrs = new FlSouto\HtAttrs([
'name' => 'test',
'onclick' => 'alert("Test!")'
]);
$attrs['style']['color'] = 'black';
// it's also possible to get the object:
$style = $attrs['style'];
$style['padding'] = '5px';
echo "<a $attrs>Click me</a>";
The above code outputs:
<a name="test" onclick="alert("Test!")" style="color:black;padding:5px">Click me</a>
统计信息
- 总下载量: 224
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2016-10-24