adilab/html

Adi HTML Tools for PHP

v1.0.0 2016-04-16 19:12 UTC

This package is not auto-updated.

Last update: 2024-09-20 19:14:50 UTC


README

Adi HTML Tools for PHP 是一组用于在 PHP 中直接准备 HTML 代码的类。该集合包含用于处理基本 HTML 标签的内容类,以及从数组中获取数据来创建 HTML 表格代码的类。

安装

首选安装方法是使用 Composer

使用 composer 安装此库

$ composer require adilab/html

用法

Tag 类的用法。 在线演示。

require('vendor/autoload.php');

use Adi\Html\Tag;

$p = new Tag('p', 'Hello world');
$p->addStyle('color: #ff0000')->addStyle('background-color', '#ccc');
echo $p->render();

复杂 HTML 结构的用法。 在线演示。

require('vendor/autoload.php');

use Adi\Html\Div;
use Adi\Html\Strong;

echo Div::create(Strong::create('Hello world'))->setStyle('color: #ff0000');

Table 类的用法。 在线演示。

require('vendor/autoload.php');
use Adi\Html\Table\Table;
use Adi\Html\Table\Tr;
use Adi\Html\Table\Td;

$data = array(
    array('aaa', 'bbb', Td::create('ccc')->addClass('ccc')),
    array('ddd', 'eee', 'fff'),
    Tr::create(array('ggg', 'hhh', 'iii'))->addClass('selected'),
);

echo Table::create($data);

Table 类 - 命名列的用法。 在线演示。

require('vendor/autoload.php');
use Adi\Html\Table\Table;
use Adi\Html\Table\Th;
use Adi\Html\Table\Tr;
use Adi\Html\Table\Column;
use Adi\Html\Table\Td;

$data = array(
    array('A' => 'aaa', 'B' => 'bbb', 'C' => 'ccc'),
    array('A' => 'ddd', 'B' => 'eee', 'C' => 'fff'),
    array('A' => 'ggg', 'B' => 'hhh', 'C' => Td::create('iii')->setId('i')),
);

$table = new Table($data);
$table->setColumn('B', Column::create()->addStyle('color', '#ff0000'));
$table->setHeader('B', '[B]');
$table->setHeader('C', Th::create('[C]')->addStyle('color', '#0000ff'));
echo $table;

文档

API 文档