PHP code example of recoded-dev / wordpress-block-parser

1. Go to this page and download the library: Download recoded-dev/wordpress-block-parser 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/ */

    

recoded-dev / wordpress-block-parser example snippets




use Recoded\WordPressBlockParser\BlockParser;
use Recoded\WordPressBlockParser\Blocks\Block;
use Recoded\WordPressBlockParser\BlockReplacer;

$content = <<<HTML
<!-- wp:paragraph -->
Test
<!-- /wp:paragraph -->
HTML;

$parser = BlockParser::create($content);
$replacer = BlockReplacer::create($content);

foreach ($parser as $block) {
    // $block->namespace
    // $block->name
    // $block->attributes

    if ($block instanceof Block) {
        // $block->content
    }

    $replacer->replace($block, 'Your replaced content');
}

echo (string) $replacer; // Your replaced content