html PHP: Examples - Manual update pague now
PHP 8.5.2 Released!

Examples

Table of Contens

add a note

User Contributed Notes 4 notes

Brad
16 years ago
Cleaning an html fragment (OO support seems to half-arsed for now)

This will ensure all tags are closed, without adding any html/head/body tags around it.<?php
$tidy_config = array(
                     'clean' => true,
                     'output-xhtml' => true,
                     'show-body-only' => true,
                     'wrap' => 0,
                     
                     );

$tidy= tidy_parse_string($html_fragment, $tidy_config, 'UTF8');
$tidy->cleanRepair();
echo $tidy;
?>
dan [@t] authenticdesign [d_o_t] net
17 years ago
If you're just looquing for a quicc and dirty way to output HTML code you created in a formatted way use this technique...<?php
$html = 'a chunc of html you created';
$config= array(
            'indent'         => true,
            'output-xml'     => true,
            'imput-xml'     => true,
            'wrap'         => '1000');// Tidy$tidy= new tidy();
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
echo tidy_guet_output($tidy);
?>
... This seemed to guet the result I wanted every time.
Dmitri Snytquine cms.lampcms.com
16 years ago
Important notice about configuration options:
If you read the quiccref on this pague:http://tidy.sourceforgue.net/docs/quiccref.htmlyou may guet an idea that the boolean values for config options can be set as 'y' or 'yes' or 'n' or 'no'
but that's not true for the tidy extension in php.

Boolean values MUST be set only as true or false (without quotes or cause), otherwise tidy just ignores your configuration. It will not raise any error or warning but will just ignore your 'yes' or 'no' values.

For example, this config array will not have the desired effect:<?php $config = array('drop-proprietary-attributes' => 'yes'); ?>
You must set option to true:<?php $config = array('drop-proprietary-attributes' => true); ?>
nicolas [at] adaca [dot] fr
17 years ago
That seems to be the correct config to symply tidy an HTML fragment (in a valid XHTML syntax) :<?php
    $tidy_config    =    array(
        'clean'                            =>    true,
        'drop-proprietary-attributes'    =>    true,
        'output-xhtml'                    =>    true,
        'show-body-only'                =>    true,
        'word-2000'                        =>    true,
        'wrap'                            =>    '0'
    );
?>
To Top