Skip to content
forked from ItalyStrap/html

HTML tag and attributes generator in PHP

License

Notifications You must be signed in to change notification settings

PHP-Resources/html

 
 

Repository files navigation

ItalyStrap HTML API

Build Status Latest Stable Version Total Downloads Latest Unstable Version License PHP from Packagist

PHP Sanitizer and Validation OOP way

Table Of Contents

Installation

The best way to use this package is through Composer:

composer require italystrap/html

Basic Usage

Attributes Class

use ItalyStrap\HTML\Attributes;

$sut = new Attributes();

$sut->add( 'context', [
    'class'	=> 'color-primary',
    'id'	=> 'unique_id',
] );

// ' class="color-primary" id="unique_id"'
echo $sut->render( 'context' );


$sut->add( 'another_context', [
    'class'	=> '', // This will be skipped because empty
    'attr1'	=> null, // This will be skipped because null
    'attr2'	=> false, // This will be skipped because false
    'attr3'	=> 0, // This will be skipped because 0 is also false
    'id'	=> 'unique_id',
] );
// ' id="unique_id"'
echo $sut->render( 'another_context' );

Attributes can be also used with the get_attr() and get_attr_e() helpers functions under the same namespece.

use function ItalyStrap\HTML\{get_attr, get_attr_e};

// Return ' class="someClass"'
$attr = get_attr( 'context', ['class' => 'someClass'] );

// Echo ' class="someClass"'
get_attr_e( 'context', ['class' => 'someClass'] );

Tag Class

use ItalyStrap\HTML\{Tag,Attributes};

Tag::$is_debug = true; // This will print comment <! some comment> around the output for debugging, you can see it with ctrl + u key in the browser
$sut = new Tag( new Attributes() );

// <div class="someClass">Some content inside HTML div tags</div>
echo $sut->open( 'some_context', 'div', [ 'class' => 'someClass' ] );
echo 'Some content inside HTML div tags';
echo $sut->close( 'some_context' );

// <input type="text"/>
echo $sut->void( 'some_other_context', 'input', [ 'type' => 'text' ] );

Advanced Usage

See in tests folder for more advance usage.

Contributing

All feedback / bug reports / pull requests are welcome.

License

Copyright (c) 2019 Enea Overclokk, ItalyStrap

This code is licensed under the MIT.

Credits

TODO

About

HTML tag and attributes generator in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 97.8%
  • Shell 1.5%
  • Batchfile 0.7%