devscast/editorjs

PHP backend for Editor.js

dev-main 2025-04-18 11:57 UTC

This package is auto-updated.

Last update: 2025-04-18 11:57:14 UTC


README

PHP Version Require Latest Stable Version Total Downloads License

EditorJS Backend is a library for parsing, validating, and sanitizing JSON data generated by the Editor.js rich text editor. It provides a robust and extensible way to handle Editor.js blocks in PHP applications.

Installation

composer require devscast/editorjs

Basic Usage

Parsing and Sanitizing Editor.js Data The Editor class is the main entry point for processing Editor.js JSON data. It parses the JSON into blocks, validates the structure, and sanitizes the resulting HTML output.

<?php

use Devscast\EditorJs\Editor;

$data = <<<JSON
{
    "time": 1635603431943,
    "blocks": [
        {
            "id": "1",
            "type": "header",
            "data": {
                "text": "Hello, Editor.js!",
                "level": 2
            }
        },
        {
            "id": "2",
            "type": "paragraph",
            "data": {
                "text": "This is a paragraph block."
            }
        }
    ],
    "version": "2.31.0"
}
JSON;

$editor = new Editor($data);

// Get sanitized HTML output
echo $editor->getHtml();