PHP code example of wackowiki / htmlsax3

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

    

wackowiki / htmlsax3 example snippets





HTMLSax3\HTMLSax3;

// Define a handler object containing your SAX callbacks.
$handler = new class {
    public function openHandler(HTMLSax3 $parser, string $tag, array $attrs): void
    {
        echo "open: <$tag>\n";
        print_r($attrs);
    }

    public function closeHandler(HTMLSax3 $parser, string $tag): void
    {
        echo "close: </$tag>\n";
    }

    public function dataHandler(HTMLSax3 $parser, string $data): void
    {
        echo 'data: ' . trim($data) . "\n";
    }

    public function escapeHandler(HTMLSax3 $parser, string $data): void
    {
        echo 'escape: ' . trim($data) . "\n";
    }

    public function piHandler(HTMLSax3 $parser, string $target, string $data): void
    {
        echo "pi: <?$target $data

$parser->set_object($myHandler);

$parser->set_option('XML_OPTION_CASE_FOLDING');
$parser->set_option('XML_OPTION_ENTITIES_PARSED');
$parser->set_option('XML_OPTION_LINEFEED_BREAK');

class MyHandler
{
    public function openHandler(HTMLSax3 $parser, string $tag, array $attrs): bool;
    public function closeHandler(HTMLSax3 $parser, string $tag): bool;
    public function dataHandler(HTMLSax3 $parser, string $data): bool;
    public function escapeHandler(HTMLSax3 $parser, string $data): bool;
    public function piHandler(HTMLSax3 $parser, string $target, string $data): bool;
    public function jaspHandler(HTMLSax3 $parser, string $data): bool;
}

// Shim for legacy code that referenced the old root-namespace StateParser.
if (!class_exists('HTMLSax3\StateParser', false)) {
    class_alias(\HTMLSax3\States\StateParser::class, 'HTMLSax3\StateParser');
}

src/
├── helpers.php                # HTMLSax3\tap() helper
├── HTMLSax3.php               # User-facing facade (namespace HTMLSax3)
├── NullHandler.php            # No-op default handler (namespace HTMLSax3)
├── Decorators/
│   ├── CaseFolding.php        # namespace HTMLSax3\Decorators
│   ├── Entities_Parsed.php
│   ├── Entities_Unparsed.php
│   ├── Escape_Stripper.php
│   ├── Linefeed.php
│   ├── Tab.php
│   └── Trim.php
└── States/
    ├── StateParser.php        # State-machine coordinator
    │                          # (namespace HTMLSax3\States;
    │                          #  also declares STATE_* constants)
    ├── ClosingTagState.php    # namespace HTMLSax3\States
    ├── EscapeState.php
    ├── JaspState.php
    ├── OpeningTagState.php
    ├── PiState.php
    ├── StartingState.php
    └── TagState.php