PHPackages                             codex-team/codex.editor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. codex-team/codex.editor

ActiveLibrary

codex-team/codex.editor
=======================

PHP backend implementation for the Editor.js

v2.0.7(5y ago)264306↓100%48[11 issues](https://github.com/editor-js/editorjs-php/issues)[3 PRs](https://github.com/editor-js/editorjs-php/pulls)MITPHPPHP &gt;=5.6

Since Sep 30Pushed 1y ago22 watchersCompare

[ Source](https://github.com/editor-js/editorjs-php)[ Packagist](https://packagist.org/packages/codex-team/codex.editor)[ RSS](/packages/codex-team-codexeditor/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Editor.js PHP
=============

[](#editorjs-php)

Server-side implementation sample for the Editor.js. It contains data validation, HTML sanitization and converts output from Editor.js to the Block objects.

Installation
============

[](#installation)

To install lib use composer:

```
composer require codex-team/editor.js:dev-master

```

Guide
=====

[](#guide)

Add this line at the top of your PHP script

```
use \EditorJS\EditorJS;
```

this line allows you to get editors class that has the following method:

`getBlocks` - return array of sanitized blocks

Basic usage
===========

[](#basic-usage)

You can get data from editor and send as param to editor's server validator like

```
try {
    // Initialize Editor backend and validate structure
    $editor = new EditorJS( $data, $configuration );

    // Get sanitized blocks (according to the rules from configuration)
    $blocks = $editor->getBlocks();

} catch (\EditorJSException $e) {
    // process exception
}
```

Editor.js constructor has the following arguments:

`$data` — JSON string with data from CodeX Editor frontend.

`$configuration` — JSON string with CodeX Editor tools configuration (see an example in the following paragraph).

Configuration file
==================

[](#configuration-file)

You can manually configure validation rules for different types of Editor.js tools (header, paragraph, list, quote and other). You can also extend configuration with new tools.

Sample validation rule set:

```
{
  "tools": {
    "header": {
      "text": {
        "type": "string",
        "required": true,
        "allowedTags": "b,i,a[href]"
      },
      "level": {
        "type": "int",
        "canBeOnly": [2, 3, 4]
      }
    }
  }
}

```

Where:

`tools` — array of supported Editor.js tools.

`header` — defines `header` tool settings.

`text` and `level` — parameters in `header` tool structure.

`text` is a **required** *string*, which will be sanitized except *b*, *i* and *a\[href\]* tags.

`level` is an **optional** *integer* that can be only 0, 1 or 2.

`allowedTags` param should follow [HTMLPurifier](https://github.com/ezyang/htmlpurifier) format.

#### There are three common parameters for every block:

[](#there-are-three-common-parameters-for-every-block)

1. `type` (**required**) — type of the block

valuedescription`string`field with string value`int`/`integer`field with integer value`bool`/`boolean`field with boolean value`array`field with nested fields2. `allowedTags` (optional) — HTML tags in string that won't be removed

valuedefaultdescription`empty`yesall tags will be removed`*`noall tags are allowedOther values are allowed according to the [HTMLPurifier](https://github.com/ezyang/htmlpurifier) format.

Example:

```
"paragraph": {
    "text": {
        "type": "string",
        "allowedTags": "i,b,u,a[href]"
    }
}

```

3. `canBeOnly` (optional) — define set of allowed values

Example:

```
"quote": {
      "text": {
        "type": "string"
      },
      "caption": {
        "type": "string"
      },
      "alignment": {
        "type": "string",
        "canBeOnly": ["left", "center"]
      }
    }

```

### Short settings syntax

[](#short-settings-syntax)

Some syntax sugar has been added.

Tool settings can be a `string`. It defines tool's type with default settings.

```
"header": {
  "text": "string",
  "level": "int"
}
```

It evaluates to:

```
"header": {
  "text": {
    "type": "string",
    "allowedTags": "",
    "required": true
  },
  "level": {
    "type": "int",
    "allowedTags": "",
    "required": true
  }
}
```

Tool settings can be an `array`. It defines a set of allowed values without sanitizing.

```
"quote": {
  "alignment": ["left", "center"],
  "caption": "string"
}
```

It evaluates to:

```
"quote": {
  "alignment": {
    "type": "string",
    "canBeOnly": ["left", "center"]
  },
  "caption": {
      "type": "string",
      "allowedTags": "",
      "required": true
    }
}
```

Another configuration example: [/tests/samples/syntax-sugar.json](/tests/samples/syntax-sugar.json)

### Nested tools

[](#nested-tools)

Tools can contain nested values. It is possible with the `array` type.

Let the JSON input be the following:

```
{
    "blocks": [
        "type": list,
        "data": {
            "items": [
                "first", "second", "third"
            ],
            "style": {
                "background-color": "red",
                "font-color": "black"
            }
        }
    ]
}

```

We can define validation rules for this input in the config:

```
"list": {
  "items": {
    "type": "array",
    "data": {
      "-": {
        "type": "string",
        "allowedTags": "i,b,u"
      }
    }
  },
  "style": {
      "type": "array",
      "data": {
        "background-color": {
            "type": "string",
            "canBeOnly": ["red", "blue", "green"]
        },
        "font-color": {
            "type": "string",
            "canBeOnly": ["black", "white"]
        }
      }
  }
}

```

where `data` is the container for values of the array and `-` is the special shortcut for values if the array is sequential.

Another configuration example: [/tests/samples/test-config.json](/tests/samples/test-config.json)

Exceptions
==========

[](#exceptions)

### EditorJS class

[](#editorjs-class)

Exception textCauseJSON is emptyEditorJS initiated with empty `$json` argumentWrong JSON format: `error``json_decode` failed during `$json` processingInput is null`json_decode` returned null `$data` objectInput array is empty`$data` is an empty arrayField `blocks` is missing`$data` doesn't contain 'blocks' keyBlocks is not an array`$data['blocks']` is not an arrayBlock must be an Arrayone element in `$data['blocks']` is not an array### BlockHandler class

[](#blockhandler-class)

Exception textCauseTool `**TOOL\_NAME**` not found in the configurationConfiguration file doesn't contain **TOOL\_NAME** in `tools{}` dictionaryNot found required param `**key**`**key** tool param exists in configuration but doesn't exist in input data. *(Params are always required by default unless `required: false` is set)*Found extra param `**key**`Param **key** exists in input data but doesn't defined in configurationOption `**key**` with value `**value**` has invalid value. Check canBeOnly param.Parameter must have one of the values from **canBeOnly** array in tool configurationOption `**key**` with value `**value**` must be **TYPE**Param must have type which is defined in tool configuration *(string, integer, boolean)*Unhandled type `**elementType**`Param type in configuration is invalid### ConfigLoader class

[](#configloader-class)

Exception textCauseConfiguration data is emptyEditorJS initiated with empty `$configuration` argumentTools not found in configurationConfiguration file doesn't contain `tools` keyDuplicate tool `**toolName**` in configurationConfiguration file has different tools with the same nameMake Tools
==========

[](#make-tools)

If you connect a new Tool on the frontend-side, then you should create a configuration rule for that Tool to validate it on server-side.

Repository
----------

[](#repository)

[](https://github.com/codex-editor/editorjs-php/)

About CodeX
-----------

[](#about-codex)

We are small team of Web-developing fans consisting of IFMO students and graduates located in St. Petersburg, Russia. Feel free to give us a feedback on [](mailto::team@ifmo.su)

###  Health Score

38

↑

LowBetter than 86% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~155 days

Total

5

Last Release

2109d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/09eced8d4fa0c7717b174485043d7dcbd020f713c1decdab69a69fd0ca3d1eb3?d=identicon)[codex-team](/maintainers/codex-team)

---

Top Contributors

[![n0str](https://avatars.githubusercontent.com/u/988885?v=4)](https://github.com/n0str "n0str (66 commits)")[![khaydarov](https://avatars.githubusercontent.com/u/6507765?v=4)](https://github.com/khaydarov "khaydarov (38 commits)")[![neSpecc](https://avatars.githubusercontent.com/u/3684889?v=4)](https://github.com/neSpecc "neSpecc (17 commits)")[![talyguryn](https://avatars.githubusercontent.com/u/15259299?v=4)](https://github.com/talyguryn "talyguryn (6 commits)")[![johnpuddephatt](https://avatars.githubusercontent.com/u/8030910?v=4)](https://github.com/johnpuddephatt "johnpuddephatt (2 commits)")[![gohabereg](https://avatars.githubusercontent.com/u/23050529?v=4)](https://github.com/gohabereg "gohabereg (1 commits)")[![dzantiev](https://avatars.githubusercontent.com/u/411049?v=4)](https://github.com/dzantiev "dzantiev (1 commits)")[![rendom](https://avatars.githubusercontent.com/u/1078548?v=4)](https://github.com/rendom "rendom (1 commits)")[![auchanhub](https://avatars.githubusercontent.com/u/34035978?v=4)](https://github.com/auchanhub "auchanhub (1 commits)")

---

Tags

codexcodex-editorhtmlpurifier

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/codex-team-codexeditor/health.svg)

```
[![Health](https://phpackages.com/badges/codex-team-codexeditor/health.svg)](https://phpackages.com/packages/codex-team-codexeditor)
```

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.1M95](/packages/mews-purifier)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[yiisoft/yii2

Yii PHP Framework Version 2

36928.9M8.9k](/packages/yiisoft-yii2)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5245.4M14](/packages/stevebauman-purify)[caxy/php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

22320.4M11](/packages/caxy-php-htmldiff)[exercise/htmlpurifier-bundle

HTMLPurifier integration for your Symfony project

27511.1M13](/packages/exercise-htmlpurifier-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
