Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos

Home » Php » how to use ckeditor 5 in php

How To Use Ckeditor 5 In Php

how to use ckeditor 5 in php

Posted on January 30, 2022December 11, 2022 By XpertPhp

In this tutorial, We will show you how to use CKEditor 5 in PHP. we can easily install CKEditor 5 and use it. so we will give you a simple example of how to use ckeditor 5 with php.

CKEditor 5 is an Open Source text editor. which is provide lots of features such as Formatting features, Basic text styles, font features, image features, embed media into our content. if you want to know more about CKEditor 5 features then you can visit the CKEditor 5 official site.

how to use CKEditor 5 in html

In this example, we will use the ckeditor cdn js file and crate form. so we can easily implement the ckeditor 5 in html.
index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>how to use ckeditor 5 in php - XpertPhp</title>
<script src="https://cdn.ckeditor.com/ckeditor5/31.1.0/classic/ckeditor.js"></script>
    </head>
    <body>
        <form method="post" action="add.php">
            <textarea name="editor" id="editor" rows="10" cols="80">
                This is my textarea to be replaced with CKEditor 5.
            </textarea>
<p><input type="submit" name="btnSubmit" value="submit" /></p>
        </form>
<script>
ClassicEditor
            .create( document.querySelector( '#editor' ) )
            .catch( error => {
                console.error( error );
            } );
</script>
    </body>
</html>

ckeditor 5 php Code Example

Now, we can also use with php. if want to store data into databse then you can see our php example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
if($_POST['btnSubmit']){
$content = base64encode($_POST['editor']);
// Create connection
$conn = new mysqli("localhost", "root", "", "dbtest");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
 
$sql = "INSERT INTO post (content) VALUES ('".$content."')";
 
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
 
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>how to use ckeditor 5 in php - XpertPhp</title>
<script src="https://cdn.ckeditor.com/ckeditor5/31.1.0/classic/ckeditor.js"></script>
    </head>
    <body>
        <form method="post" action="add.php">
            <textarea name="editor" id="editor" rows="10" cols="80">
                This is my textarea to be replaced with CKEditor 5.
            </textarea>
<p><input type="submit" name="btnSubmit" value="submit" /></p>
        </form>
<script>
ClassicEditor
.create( document.querySelector( '#editor' ) )
.catch( error => {
console.error( error );
} );
</script>
    </body>
</html>
See also  Dynamic Dependent Dropdown in PHP using jQuery AJAX

Read CKEditor data from Database

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Read CKEditor data from Database</title>
    </head>
    <body>
        <?php
        $mysqli = new mysqli("localhost", "root", "", "dbtest");
        if ($mysqli->connect_errno) {
            echo "Failed to connect to MySQL: " . $mysqli->connect_error;
            exit();
        }
        $sql = "SELECT * FROM post order by id desc limit 1";
        echo "<h2>Displaying content from database</h2>";
        if ($result = $mysqli->query($sql)) {
            $row = $result->fetch_assoc()
            $content = base64decode($row['content']);
            echo $content;
        }
        $mysqli->close();
        ?>
    </body>
</html>

Php

Post navigation

Previous Post: Node js convert image to base64 Example
Next Post: PHP Registration with Email Verification using OTP

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com