1. Go to this page and download the library: Download crell/htmlmodel 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/ */
crell / htmlmodel example snippets
// Create an HtmlPage object.
$html = new HtmlPage();
// Populate it with various elements and body contents.
$html = $html
->withTitle('Test page')
->withHtmlAttribute('manifest', 'example.appcache')
->withBodyAttribute('foo', 'bar')
->withBase(new BaseElement('http://www.example.com/'))
->withHeadElement(new MetaRefreshElement(3, 'http://www.google.com'))
->withHeadElement(new LinkElement('canonical', 'http://www.example.com/'))
->withScript(new ScriptElement('header.js'))
->withScript(new ScriptElement('footer.js'), 'footer')
->withStyleLink(new StyleLinkElement('css.css'))
->withInlineStyle(new StyleElement('CSS here'))
->withContent('Body here')
;
// Simply casting the page object to a string will produce the corresponding markup.
$output = (string)$html;
// Create an HtmlFragment (or return one from some lower-level routine)
$src = new HtmlFragment();
$src = $src
->withHeadElement(new MetaRefreshElement(3, 'http://www.google.com'))
->withHeadElement(new LinkElement('canonical', 'http://www.example.com/'))
->withScript(new ScriptElement('js.js'))
->withScript(new ScriptElement('footer.js'), 'footer')
->withScript($inline_script)
->withStyleLink(new StyleLinkElement('css.css'))
->withInlineStyle(new StyleElement('CSS here'))
->withContent('Body here')
;
// Now make an HtmlPage.
$dest = new HtmlPage();
// Now shuffle the metadata from the fragment to the page.
$transferer = new AggregateMetadataTransferer([
StyleContainerInterface::class => new StyleTransferer(),
ScriptContainerInterface::class => new ScriptTransferer(),
StatusCodeContainerInterface::class => new StatusCodeTransferer(),
HeadElementContainerInterface::class => new HeadElementTransferer(),
]);
$html = $transferer->transfer($src, $dest);
// Now take other fragments and transfer their metadata to the page, aggregating them together!
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.