2017 © Pedro Peláez
 

library html

HTML generation library

image

brick/html

HTML generation library

  • Thursday, May 31, 2018
  • by BenMorel
  • Repository
  • 1 Watchers
  • 1 Stars
  • 378 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 57 % Grown

The README.md

Brick\Html

, (*1)

A very simple HTML 5 generation library., (*2)

Build Status Coverage Status Latest Stable Version License, (*3)

Installation

This library is installable via Composer:, (*4)

composer require brick/html

Requirements

This library requires PHP 7.1 or later., (*5)

Project status & release process

This library is still under development., (*6)

The current releases are numbered 0.x.y. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), y is incremented., (*7)

When a breaking change is introduced, a new 0.x version cycle is always started., (*8)

It is therefore safe to lock your project to a given release cycle, such as 0.1.*., (*9)

If you need to upgrade to a newer release cycle, check the release history for a list of changes introduced by each further 0.x.0 version., (*10)

Introduction

This library contains a single class, Tag, that represents an HTML tag. You construct a Tag using a tag name:, (*11)

use Brick\Html\Tag;

$div = new Tag('div');

Attributes

You can pass an optional associative array of attributes to the constructor:, (*12)

$div = new Tag('div', [
    'id' => 'main',
    'class' => 'block',
]);

Or you can set attributes later:, (*13)

$tag->setAttributes([
    'id' => 'main',
    'class' => 'block',
]);

Or:, (*14)

$tag->setAttribute('id', 'main')
    ->setAttribute('class', 'block');

You can also remove attributes:, (*15)

$tag->removeAttribute('id');

Content

You can set the content of a Tag, provided that it's not a void tag such as <br>, <input>, etc. If you try to modify the content of a void tag, you'll get a LogicException., (*16)

You can set or append a plain text content:, (*17)

$tag->setTextContent('Hello, world!');
$tag->appendTextContent("\nWhat's up?");

Or set/append a HTML content:, (*18)

$tag->setHtmlContent('Hello, <b>world!</b>');
$tag->appendHtmlContent("<br>What's up?");

You can also append another Tag:, (*19)

$tag->append($otherTag);

You can remove the content of a Tag:, (*20)

$tag->empty();

You can check if a Tag has an empty content:, (*21)

$tag->isEmpty(); // boolean

Rendering a tag

You can render a tag by using its render() method, or just by casting it to string:, (*22)

echo $tag; // will output something like: <div id="main">Hello, world!</div>

Encoding

All texts (attributes, content) are expected to be valid UTF-8., (*23)

The Versions

31/05 2018

dev-master

9999999-dev

HTML generation library

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

html brick

06/10 2017

0.1.1

0.1.1.0

HTML generation library

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

html brick

06/10 2017

0.1.0

0.1.0.0

HTML generation library

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

html brick