zhalker/dumb-artifact-for-multi-level-contextual-parsing-in-php

An unnecessarily complex tool that replaces patterns through multi-level contextual parsing in PHP. Dumb, yet somehow useful

Maintainers

Package info

github.com/zhalker/dumb-artifact-for-multi-level-contextual-parsing-in-php

pkg:composer/zhalker/dumb-artifact-for-multi-level-contextual-parsing-in-php

Statistics

Installs: 19

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

v1.2.0 2025-10-28 23:42 UTC

This package is auto-updated.

Last update: 2026-03-29 01:13:43 UTC


README

An unnecessarily complex tool that performs multi-level contextual text replacements in PHP. Useful for transforming text inside nested or scoped contexts while skipping comments and handling escapes.

Installation

Require the package with Composer (replace your-vendor/your-repo with the repository name you publish on GitHub/Packagist):

composer require zhalker/dumb-artifact-for-multi-level-contextual-parsing-in-php

Note: locally the package is autoloaded via the vendor/autoload.php generated by Composer.

Namespace and autoloading

This library uses PSR-4 autoloading. The base namespace is DumbContextualParser\ and maps to the src/ directory.

Example class: DumbContextualParser\ContextualReplaceText

Basic usage example

<?php
require __DIR__ . '/vendor/autoload.php';

use DumbContextualParser\ContextualReplaceText;

$text = "<html>\n<!-- ignore this comment -->\n<body>";

$rules = [
    [
        'scope_start' => '<body>',
        'scope_end' => '</body>',
        'self_replace' => [
            'open' => '"',
            'close' => '"',
            'pattern' => '<em>%s</em>'
        ],
        'inner_scopes' => []
    ]
];

$result = ContextualReplaceText::applyContexts($text, $rules);

echo $result;

Notes

  • The repository package name (zhalker/dumb-artifact-for-multi-level-contextual-parsing-in-php) can stay as-is for GitHub/Packagist; the PHP namespace used in code is DumbContextualParser\.
  • Consider adding tests (PHPUnit) and an examples/ directory with runnable examples.

License

MIT