PHP code example of tekintian / html-cleaner

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

    

tekintian / html-cleaner example snippets




use tekintian\HtmlCleaner\HtmlCleaner;

// Clean HTML string
$dirtyHtml = '<p style="color: red;">Content</p>';
$cleanHtml = HtmlCleaner::clean($dirtyHtml);

// Clean HTML file
$cleanedHtml = HtmlCleaner::cleanFile('input.html', 'output.html');

use tekintian\HtmlCleaner\HtmlCleaner;

$tagLinks = [
    'PHP' => 'https://www.php.net/manual/en/',
    'JavaScript' => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript',
    'Python' => 'https://docs.python.org/3/',
];

$cleanedHtml = HtmlCleaner::clean($html, $tagLinks);

use tekintian\HtmlCleaner\HtmlCleaner;

// Custom processing pipeline
$html = HtmlCleaner::unifiedAttributeProcessing($dirtyHtml);
$html = HtmlCleaner::removeEmptyTags($html);
$html = HtmlCleaner::simplifyTags($html);
$html = HtmlCleaner::cleanWhitespace($html);

// Skip specific steps if not needed
// $html = HtmlCleaner::removeUselessAttributes($html);
// $html = HtmlCleaner::processPreTags($html);

// Apply custom processing between steps
$html = str_replace('<br>', '<br />', $html);

$cleanedHtml = $html;

// Set APP_DEBUG environment variable to control debug output
putenv('APP_DEBUG=true'); // Shows debug output
// putenv('APP_DEBUG=false'); // No debug output (default)

// Alternative: Use APP_ENV for backward compatibility
putenv('APP_ENV=dev'); // Also shows debug output

use tekintian\HtmlCleaner\HtmlCleaner;

$html = HtmlCleaner::clean($dirtyHtml);
// With debug enabled: Shows processing progress
// With debug disabled: Silent operation

class CustomHtmlCleaner extends HtmlCleaner {
    private static function getCurrentHost() {
        return 'your-domain.com'; // Custom host for external link detection
    }
}