PHP code example of uhupi / php-oop-html-tag-element

1. Go to this page and download the library: Download uhupi/php-oop-html-tag-element 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/ */

    

uhupi / php-oop-html-tag-element example snippets




// print a simple Link
$link = new Element('a', 'Click here');
$link->setAttr('href', '/');

echo $link;

// Or create your Link template
class Button extends Element {
    public function __construct($content = false, $url = false) {
        parent::__construct('a', $content, 'button');
        if ($url) {
            $this->setAttr('href', $url);
        }
        $this->setClass('button');
    }
}

// print adding your defined values like content and the url
$button = new Button('Click here', '/');
// or maybe you decide in the view or your template to add some content
if (TRUE) {
    $button->setContent(' NOW!');
}
echo $button;

// or Print it in one line if you like
echo new Button('Click here', '/');