PHP code example of wongyip / html-beautify
1. Go to this page and download the library: Download wongyip/html-beautify 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/ */
wongyip / html-beautify example snippets
use \Wongyip\HTML\Beautify;
$html = <<<HTML
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title></head>
<body><div class="row col-sm12"><ol><li></li><li></li><li></li></ol></div></body></html>
HTML;
# State-less
echo Beautify::html($html);
# Reusable
$beautifier = new Beautify();
echo $beautifier->beautify($html);
# Alternative static constructor
echo Beautify::init()->beautify($html);
use \Wongyip\HTML\Beautify;
# All options are optional.
$options = [
'indent_inner_html' => false,
'indent_char' => " ",
'indent_size' => 4,
'wrap_line_length' => 32768,
'unformatted' => ['code', 'pre'],
'preserve_newlines' => false,
'preserve_newlines_max' => 32768,
'indent_scripts' => 'normal',
];
# Set on instantiate.
$beautifier = new Beautify($options);
# Update option(s)
$beautifier->options(['indent_size' => 2]);
# Get options
$options = $beautifier->options();
bash
composer create-project wongyip/html-beautify
cd html-beautify
composer install
php demo/demo.php