Skip to content

Dom‐Wrapper

gtbu edited this page Feb 17, 2025 · 9 revisions

The PHP-Dom Wrapper is a useful tool for templates. It is similar to jquery but at the php8-level. Another similar old tool would be phpquery which is no longer supported.

A basic autoloader is 👍

spl_autoload_register(function ($class) {
    $prefix = 'Scotteh\\DOMWrapper\\';
    $base_dir = __DIR__ . '/path/to/domwrapper/src/';

    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return; // class does not use the prefix
    }

    $relative_class = substr($class, $len);

    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';

    if (file_exists($file)) {
        require $file;
    }
});
 and : require_once __DIR__ . '/vendor/scotteh/php-dom-wrapper/autoloader.php';

Clone this wiki locally