Getting started
PHP HTML Editor is a folder you copy into your site, richtexteditor. It holds the editor that runs in the browser and the PHP that answers its uploads, image gallery and file requests with the permissions you choose.
Install
- Copy
richtexteditorto your web root. - Make the upload folders writable by the web server:
uploads/images,uploads/documentsanduploads/mediaby default. They are created on first use. - Check the requirements: PHP 8 with the DOM extension, and GD for images.
Add the editor to a page
Two APIs do the same thing. The classic API is the one pages for Rich Text Editor for PHP were written with; the modern API is a namespaced class.
Classic API
<?php
require_once 'richtexteditor/include_rte.php';
$rte = new RichTextEditor();
$rte->Name = 'Body';
$rte->SecurityPolicyFile = 'default.config';
$rte->Text = load_article(); // the HTML to edit
$rte->MvcInit(); // before any output
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
save_article(RichTextEditor::GetPostedHtml('Body'));
}
?>
<form method="post">
<?php echo $rte->GetString(); ?>
<button>Save</button>
</form>
Modern API
<?php
require_once 'richtexteditor/phphtmleditor/autoload.php';
use PhpHtmlEditor\Editor;
$editor = new Editor('Body');
$editor->policyFile = 'default.config';
$editor->html = load_article();
$editor->handleRequest(); // before any output
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
save_article($editor->posted());
}
?>
<form method="post"><?= $editor->render() ?><button>Save</button></form>
How it fits together
- The form: the editor writes its HTML into a field named after the editor (
Bodyabove), so a normal form post sends it. - The server requests: uploads and the image gallery are sent to the same page with
?rte_action=....MvcInit()/handleRequest()answers them and ends the request; a normal page view continues. - The file manager: the Insert file button lists the server's documents and media; users upload, create folders, rename and delete there as their policy allows, and insert a file as a link or player. Images use Insert Gallery.
- The policy: what may be uploaded, where it is stored and who may rename or delete comes from the policy file you name. See the policy reference.
- Cleaning:
GetPostedHtml()andposted()remove scripts and other active content on the server. See security.
Next
Try the live demos, each with its PHP, or read the classic API and modern API references.