PHP code example of volux / dom

1. Go to this page and download the library: Download volux/dom 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/ */

    

volux / dom example snippets



use volux\Dom;

$htmlResult = new Dom\Html();

$htmlResult->title('Google News Test');

Dom\Html::doc()->load('http://news.google.com/news')
    ->find('.titletext')
        ->each(function ($node, $index) use ($htmlResult) {
            $htmlResult->body()
                ->append('p')
                    ->append('span')->text(($index + 1) . ': ')
                ->parent()
                    ->append('a')->attr('href', $node->parent()->attr('href'))->text($node->text());
        });

echo $htmlResult;



use volux\Dom;

Dom\Document::doc()->load('example.xml')
    ->find('.content')->xslt('content.xsl')
        ->end()
    ->saveHTMLfile('transformed.html');

/* each tags with class="content" will be transformed and replaced */

use volux\Dom;

$form = new Dom\Form();
$form
    ->fieldSet('Group 1')
        ->add()
            ->input()->name('name')
                ->placeholder('Name')
                ->  ->label('Select item')
        ->add()
            ->input('0a0b0c0d', 'hidden')->name('token')
->form()
    ->fieldSet('Group 2')
        ->add()
            ->radio('choose', array('r'=>'Red', 'g'=>'Green', 'b'=>'Blue'))
        ->add()
            ->space()
        ->add()
            ->textarea('', array('name'=>'desc'))->label('Description')
                ->rows(5)->addClass('span4')
                ->help('Input short description about it', 'help-block')
->form()
    ->checkbox('confirm', array('Confirm'))
->form()
    ->section('form-actions')
        ->add()
            ->buttonSubmit('Send as GET')
                ->addClass('btn btn-primary')
        ->add()
            ->space('h')
        ->add()
            ->buttonSubmit('Send as POST')
                ->addClass('btn btn-success')
                ->formMethod('post')
;

$html = new Dom\Html();
$html
    ->root()->attr(array('lang' => 'en'));
$html
    ->meta(array('charset' => Html::ENCODING))
    ->title('volux\Dom\Form Test')
    ->stylesheet('//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css')
    ->body()
        ->append('div')->attr('class', 'row')
            ->append('div')->attr('class', 'span4 offset1')
                ->append($form) /* point to add builded form to main html */
;

echo $html;


use volux\Dom;

$html = new Dom\Html();
$html
    ->root()->attr('lang', 'en');
$html
    ->meta(array('charset' => 'utf-8'))
    ->meta(array(
        'http-equiv' => 'X-UA-Compatible',
        'content'    => 'IE=edge,chrome=1',
    ))
    ->meta(array(
        'name'    => 'viewport',
        'content' => 'user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1',
    ))
    ->title('volux\Dom\Html Test')
    ->stylesheet('//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.no-icons.min.css')
    ->script('//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js')
    ->stylesheet('/css/app.css')
    ->script('/js/app.js');

$navBarInner = $html
    ->body()
        ->a('header', array('class' => 'navbar navbar-fixed-top'))
            ->a('div', array('class' => 'navbar-inner'))
                ->a('a', array(
                        'class' => 'brand image',
                        'href'  => '/',
                        'title' => 'volux\Dom\Html Test')
                    )
                    ->append('<strong>volux\Dom\Html Test</strong>')
                ->parent()
            ->parent()
                ->a('ul', array('class' => 'nav'))
                    ->a('li', array('class' => 'divider-vertical'), false)
                ->parent()
            ->parent();

$html->body()->append('div')
    ->id('main')
    ->addClass('some test content') /* for example */
    ->removeClass('test some') /* for example */
        ->append('p')
            ->attr('class', 'p3')
            ->append('1. Text with <em>entity</em> &copy;<br>and ')
                ->append('<a href="#"><i class="icon-2"> </i>valid xml </a>')
            ->parent()
                ->append(' And<br>any more text.')
            ->parent()
        ->before('h1')
            ->append('Value with<br><span class=test>not valid xml');

echo $html;
/**
* you can use $navBarInner for add some element later:
*
* for example $navBarInner->load($templateDir.'menu.html')
*
* or $navBarInner->a('ul', array('class' => 'nav'))
*     ->l('li', array(
*      	  array('>' => 'a', 'First', 'href' => '/item1'),
*      	  array('>' => 'a', 'Second', 'href' => '/item2'),
*     ));
*/