PHP code example of ouxsoft / phpmarkup

1. Go to this page and download the library: Download ouxsoft/phpmarkup 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/ */

    

ouxsoft / phpmarkup example snippets




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;
    }
}



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'));
$processor->parseBuffer();