PHP code example of alexsasharegan / html

1. Go to this page and download the library: Download alexsasharegan/html library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alexsasharegan / html example snippets




stantiation
$div = new Html; # defaults to an empty 'div'
$button = new Html('button'); # specify the tagName
$p = new Html('p', 'This is a paragraph with some content.'); # specify inner element text

// Set element id
$appDiv = (new Html)->id('app');

// Adding classes
$div = new Html; # create a new div
$div->addClass('item'); # add class .item
$div->addClasses(['col-lg-3', 'col-md-4', 'col-sm-6']); # add multiple classes using an array

// Adding attributes
$input = new Html('input'); # create a new input
$input->addAttribute('type', 'text'); # add type="text" attr
$input->addAttributes(['arentDiv->newChild('p', 'This is some awesome chaining!');
$childForm = $parentDiv->newChild('form')->addAttribute('method', 'POST');
$childForm->newChild('input')->addAttribute('type', 'text');
$childForm->newChild('button', 'Send')->addAttribute('type', 'submit');

echo $parentDiv;
// Outputs:
//  <div class="awesome" data-toggle="tooltip" title="This is my tooltip!"
//  style="color:red">
//    <h3>Chaining</h3>
//    <p>This is some awesome chaining!</p>
//    <form method="POST">
//      <input type="text">
//      <button type="submit">Send</button>
//    </form>
//  </div>

// Static method element creation
echo Html::createElement('h1', 'Awesome, right?', [
  'style' => 'font-family:Monaco;',
  'class' => 'awesome heading',
]);
// Outputs:
// <h1 style="font-family:Monaco;" class="awesome heading">Awesome, right?</h1>