![](/img/trans.png)
[英]CodeIgniter - Save HTML content of WYSIWYG editor in a database to be used at a later date
[英]get content of wysiwyg editor and send it to html
我在所見即所得(WYSIWYG-Editors)周圍亂七八糟,想用php獲取它的當前內容,並將其附加到html上,或者說<p>
。 我必須說我是一個PHP入門者,但是我已經弄清楚了如何獲取.txt
的內容並將其echo
到html。
<?php
$textfile = "text.txt";
$text = file($textfile);
echo $text
?>
很簡單。 但是必須有可能用“所見即所得”編輯器“替換” text.txt
。
有人有暗示嗎,我真的很感激。
謝謝
編輯:詳細來說,我有一個帶有一些文本內容的網站index.html
。 我不想使用CMS
而是希望使用其他html格式,用戶可以訪問textedit.html
並在WYSIWYG
編輯器(如CK-Editor
或TinyMCE
鍵入一些句子。 textedit.html
訪問index.html
並更改定義的<p>
標記。
在大多數情況下,編輯器的內容將來自表單的POST請求。
<form action="process.php" method="POST">
<textarea name="text" id="editor"></textarea>
<input type="submit" value="Submit" />
</form>
然后在process.php
:
<?php
$content = $_POST['text'];
echo $content;
?>
當然,您必須為此添加一些驗證。 但是,這應該給您一個簡單的想法並讓您開始。
您也可以像這樣啟動Google搜索:“表單處理php”。
您需要某種服務器端操作來執行此操作。 純HTML不可能做到這一點! 您需要添加服務器端后端。
只是一些圖表來說明這一點:
editor.html
| 將更改發送到后端
v
后端(更改前端的內容)
|
v
content.html
這是一個非常糟糕的設計(直接更改html文件的內容),但是原理是相同的。 在“好的”設置中,您將擁有一個保存內容的數據庫,前端將從那里拉出,后端將推送。 但是使用純HTML則不可能!
因此,讓我給您一些樣板:
index.php:
<html>
<head>
<!-- add more stuff here -->
</head>
<body>
<h1>Your Site</h1>
<!-- add more stuff here -->
<p>
<?php
echo file_get_contents('article.txt');
?>
</p>
<!-- add more stuff here -->
</body>
</html>
editor.html:
<html>
<head>
<!-- add more stuff here -->
</head>
<body>
<h1>Your Site - Editor</h1>
<!-- add more stuff here -->
<form action="process.php" method="POST">
<input type="password" name="pwd" placeholder="Password..." />
<textarea name="text" id="editor"></textarea>
<input type="submit" value="Submit" />
</form>
<!-- add more stuff here -->
</body>
</html>
process.php:
<?php
if(!isset($_POST['text']) {
die('Please fill out the form at editor.html');
}
if($_POST['pwd'] !== 'your_password') {
die('Password incorrect');
}
file_put_contents('article.txt', $_POST['text']);
header("Location: index.php");
?>
這是一個非常基本的樣板,應該可以幫助您入門。 隨時調整。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.