1. Go to this page and download the library: Download wp-php-toolkit/html 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/ */
wp-php-toolkit / html example snippets
l = <<<'HTML'
<article>
<img src="hero.jpg" alt="Hero">
<p>Intro copy.</p>
<img src="inline.jpg" alt="Inline">
</article>
HTML;
$tags = new WP_HTML_Tag_Processor( $html );
while ( $tags->next_tag( 'img' ) ) {
// Don't clobber an explicit eager hint the author already set.
if ( null === $tags->get_attribute( 'loading' ) ) {
$tags->set_attribute( 'loading', 'lazy' );
}
$tags->set_attribute( 'decoding', 'async' );
}
echo $tags->get_updated_html();
"attribute: " . WP_HTML_Decoder::decode_attribute( 'path?a=1&b=2&copy' ) . "\n";
echo "text: " . WP_HTML_Decoder::decode_text_node( 'AT&T — 100% 😀' ) . "\n";
// Safe URL prefix check that decodes character references while comparing.
// `j` is the letter `j`, so this string really does start with javascript:.
// strpos() would miss it.
$is_javascript = WP_HTML_Decoder::attribute_starts_with(
'javascript:alert(1)',
'javascript:',
'ascii-case-insensitive'
);
var_dump( $is_javascript );