A Processor for Markup written in PHP. Allows extraction of Markup into a data structure, orchestrated nested manipulation of said structure, and output as (optimized) Markup.

v4.3.2 2022-01-02 08:06 UTC


CI Code Quality Code Coverage Docs Status

Latest Stable Version PHP Versions Supported License Total Downloads


Install the latest version:

$ composer require ouxsoft/phpmarkup

Basic Usage

Create an Element class containing DOMElement processing instructions.


namespace App\Elements;

class Messages extends Ouxsoft\PHPMarkup\Element
    private $messages;

    public function onLoad() : void
        $this->messages = $this->db->query('SELECT `msg` FROM `messages`;');

    public function onRender(): string
        $out = '';
        foreach($this->messages as $row){
            $out .= $row['msg'] . $this->getArgByName('delimiter');
        return $out;

Configure a Processor to process a DOM using the Element class created.


use Ouxsoft\PHPMarkup\Factory\ProcessorFactory;
use App\Elements\Messages;

$processor = ProcessorFactory::getInstance();
$processor->addElement(['xpath' => '//messages', 'class_name' => App\Elements\Messages::class]);
$processor->addRoutine(['method' => 'onLoad']);
$processor->addRoutine(['method' => 'onRender', 'execute' => 'RETURN_CALL']);
$processor->addProperty('db', new PDO('sqlite:/example.db'));
<html lang="en">
        <arg name="delimiter">;</arg>


PHPMarkup is a lightweight markup processor written in PHP. It facilitates the extraction of markup into a data structure, orchestrated manipulation of said structure, and output as (optimized) markup. It is based on the LHTML standard.



Matthew Heroux
See also the list of contributors who participated in this project.


PHPMarkup is an open source project. If you find a problem or want to discuss new features or improvements please create an issue, and/or if possible create a pull request. Easily contribute using test docker image.


PHPMarkup is licensed under the MIT License - see the LICENSE file for details.


Thanks to Andy Beak for providing code reviews. Thanks to Bob Crowley for providing Project Management advising. Thanks to Aswin Vijayakumar for their useful comments. Thanks to Alexander Romanovich of White Whale Web Services for his work on the free class XPHP. All of have led to changes to this implementation.