GithubHelp home page GithubHelp logo

php-html-element's Introduction

PHP HTML Element

Create and modify HTML tags in PHP the simple way with OOP classes

Installation

Installation of this module uses Composer. For Composer documentation, please refer to getcomposer.org.

Put the following into your composer.json

{
    "require": {
        "bockmist/html-element": "dev-master"
    }
}

Examples

Simple Tags

<?php

$link = new Tag('a');
$link->href = 'http://www.google.com';
$link->setText('Google this!');

echo $link->render();

Output:

<a href="http://www.google.com">Google this!</a>

Tag hierarchy

<?php

$data = array( array('1st row, column 1', '1st row, column 2'), array('2nd row, column 1', '2nd row, column 2') );

$table = new Tag('table');

foreach ( $data as $row )
{
    $tr = new Tag('tr');
    $table->addChild( $tr );
    
    foreach ( $row as $cell )
    {
        $td = new Tag('td');
        $td->setText( $cell );
        
        $tr->addChild( $td );
    }
}

echo $table;

Output:

<table><tr><td>1st row, column 1</td><td>1st row, column 2</td></tr><tr><td>2nd row, column 1</td><td>2nd row, column 2</td></tr></table>

Parse HTML

<?php

$html = "<div><h1>Hello world</h1>How do you do?</div>";

$div = Element::createFromString($html);

$div->getChild(0)->setAttribute('style', 'font-weight:25px')->setText('Hello there!');

echo $div;

Output:

<div><h1 style="font-weight:25px">Hello there!</h1>How do you do?</div>

php-html-element's People

Contributors

werner-freytag avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.