php 如何在php页面中添加或嵌入CKEditor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8151889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add or embed CKEditor in php page
提问by Rafee
how to add or embed CKEditor in php page, I downloaded and extracted the zip file into root of the directory and also called on my page
如何在php页面中添加或嵌入CKEditor,我下载了zip文件并将其解压缩到目录的根目录中,并在我的页面上调用
<?php require("ckeditor/ckeditor.php"); ?>
gave the textarea this fields
给 textarea 这个字段
<textarea class="ckeditor" name="editor1">Write any thing</textarea>
But its not working, Documentation for installation on PHP is not found CKEditor website.
但它不起作用,在 CKEditor 网站上找不到安装在 PHP 上的文档。
Does any one knows where we or help me out..for this app.
有谁知道我们在哪里或帮我解决这个应用程序。
回答by uzair
Easy steps to Integrate ckeditor with php pages
将 ckeditor 与 php 页面集成的简单步骤
step 1 : download the ckeditor.zip file
第 1 步:下载 ckeditor.zip 文件
step 2 : paste ckeditor.zip file on root directory of the site or you can paste it where the files are (i did this one )
第 2 步:将 ckeditor.zip 文件粘贴到站点的根目录中,或者您可以将其粘贴到文件所在的位置(我做了这个)
step 3 : extract the ckeditor.zip file
第 3 步:解压 ckeditor.zip 文件
step 4 : open the desired php page you want to integrate with here page1.php
第 4 步:在此处打开您想要集成的所需 php 页面 page1.php
step 5 : add some javascript first below, this is to call elements of ckeditor and styling and css without this you will only a blank textarea
第 5 步:首先在下面添加一些 javascript,这是调用 ckeditor 和样式和 css 的元素,如果没有这个,你将只有一个空白的 textarea
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
And if you are using in other sites, then use relative links for that here is one below
如果您在其他站点中使用,则使用相关链接,这是下面的一个
<script type="text/javascript" src="somedirectory/ckeditor/ckeditor.js"></script>
step 6 : now!, you need to call the work code of ckeditor on your page page1.php below is how you call it
第6步:现在!,您需要在您的页面page1.php上调用ckeditor的工作代码,下面是您的调用方式
<?php
// Make sure you are using a correct path here.
include_once 'ckeditor/ckeditor.php';
$ckeditor = new CKEditor();
$ckeditor->basePath = '/ckeditor/';
$ckeditor->config['filebrowserBrowseUrl'] = '/ckfinder/ckfinder.html';
$ckeditor->config['filebrowserImageBrowseUrl'] = '/ckfinder/ckfinder.html?type=Images';
$ckeditor->config['filebrowserFlashBrowseUrl'] = '/ckfinder/ckfinder.html?type=Flash';
$ckeditor->config['filebrowserUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$ckeditor->config['filebrowserImageUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
$ckeditor->config['filebrowserFlashUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$ckeditor->editor('CKEditor1');
?>
step 7 : what ever you name you want, you can name to it ckeditor by changing the step 6 code last line
第 7 步:无论您想命名什么,您都可以通过更改最后一行的第 6 步代码将其命名为 ckeditor
$ckeditor->editor('mycustomname');
step 8 : Open-up the page1.php, see it, use it, share it and Enjoy because we all love Open Source.
第 8 步:打开 page1.php,查看、使用、分享和享受,因为我们都喜欢开源。
Thanks
谢谢
回答by Vinit Kadkol
If you have downloaded the latest Version 4.3.4 then just follow these steps.
如果您下载了最新的 4.3.4 版,则只需按照以下步骤操作即可。
- Download the package, unzip and place in your web directory or root folder.
- Provide the read write permissions to that folder (preferably Ubuntu machines )
- Create view page test.php
- Paste the below mentioned code it should work fine.
- 下载包,解压并放置在您的 Web 目录或根文件夹中。
- 提供对该文件夹的读写权限(最好是 Ubuntu 机器)
- 创建视图页面 test.php
- 粘贴下面提到的代码它应该可以正常工作。
Load the mentioned js file
加载提到的js文件
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script> <textarea class="ckeditor" name="editor"></textarea>
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script> <textarea class="ckeditor" name="editor"></textarea>
回答by abhijeet kumar
Alternately, it could also be done as:
或者,也可以这样做:
<?php
include("ckeditor/ckeditor.php");
$CKeditor = new CKeditor();
$CKeditor->BasePath = 'ckeditor/';
$CKeditor->editor('editor1');
?>
Note that the last line is having 'editor1' as name, it could be changed as per your requirement.
请注意,最后一行的名称是“editor1”,可以根据您的要求进行更改。
回答by Francis.TM
no need to require the ckeditor.php, because CKEditor will not processed by PHP...
不需要 ckeditor.php,因为 CKEditor 不会被 PHP 处理...
you need just following the _samples directory and see what they do.
你只需要关注 _samples 目录,看看他们做了什么。
just need to include ckeditor.js by html tag, and do some configuration in javascript.
只需要通过html标签包含ckeditor.js,并在javascript中做一些配置。
回答by Govind
<?php require("ckeditor/ckeditor.php"); ?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="somedirectory/ckeditor/ckeditor.js"></script>
<textarea class="ckeditor" name="editor1"></textarea>
回答by Siraj Alam
After reading the Quick Start Guide
阅读快速入门指南后
In your HTML page add an element that CKEditor should replace:
在您的 HTML 页面中添加一个 CKEditor 应该替换的元素:
<textarea name="content" id="editor"></textarea>
Load the classic editor build (here CDN location is used):
加载经典编辑器构建(此处使用 CDN 位置):
<script src="https://cdn.ckeditor.com/ckeditor5/10.0.1/classic/ckeditor.js"></script>
Call the ClassicEditor.create() method.
调用 ClassicEditor.create() 方法。
<script>
ClassicEditor
.create( document.querySelector( '#editor' ) )
.catch( error => {
console.error( error );
} );
</script>
Example
例子
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CKEditor 5 - Classic editor</title>
<script src="https://cdn.ckeditor.com/ckeditor5/10.0.1/classic/ckeditor.js"></script>
</head>
<body>
<h1>Classic editor</h1>
<textarea name="content" id="editor">
<p>This is some sample content.</p>
</textarea>
<script>
ClassicEditor
.create( document.querySelector( '#editor' ) )
.catch( error => {
console.error( error );
} );
</script>
</body>
</html>
This example is for the specific classic editor. FOr other variants, only CDN will change.
此示例适用于特定的经典编辑器。对于其他变体,只有 CDN 会发生变化。