flsouto/htattrs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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(&quot;Test!&quot;)">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(&quot;Test!&quot;)">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(&quot;Test!&quot;)" style="color:black;padding:5px">Click me</a>

统计信息

  • 总下载量: 224
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-10-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固