Я создаю редактируемый веб-сайт для некоторых людей, я использую ckeditor, чтобы они могли использовать WYSIWYG в Интернете, но когда я использую метод post для сохранения данных, код становится испорченным...
Вот как я использую ckeditor для сохранения вкладок и всего моего редактируемого веб-сайта:
<html>
<head>
<title>CKEditor Sample</title>
<script src="ckeditor/ckeditor.js"></script>
</head>
<body>
<form action="login/updateText.php" method="post">
<p>
File being modified: <textarea name="name" id="name">about.php</textarea>
<textarea name="editor1" id="editor1">
<?php echo file_get_contents('about.php');?>
</textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script>
</p>
<p>
<input type="submit">
</p>
</form>
</body>
</html>
но после редактирования:
<div class="menuslct">
<table border="0" style="text-align:center; width:980px">
<tbody>
<tr>
<td><a href="/en/aboutus"><img src="/common/img/icons/aboutus.png" style="height:80px; width:80px" /></a></td>
<td><a href="/en/aboutus/ourteam"><img src="/common/img/icons/12 our team.jpg" style="height:78px; width:78px" /></a></td>
<td><a href="/en/aboutus/howtohelp"><img src="/common/img/icons/11 help.jpg" style="height:78px; width:78px" /></a></td>
</tr>
<tr>
<td>About Us</td>
<td>Our Team</td>
<td>How to help</td>
</tr>
</tbody>
</table>
</div>
сохраненный код html выглядит следующим образом:
<div class="\"menuslct\"">
<table border="\"0\"" style="\"height:80px">
<tbody>
<tr>
<td>About Us</td>
<td>Our Team</td>
<td>How to help</td>
</tr>
</tbody>
</table>
</div>
<p><a href="\"><img src="\" style="\"height:78px" /></a><a href="\"> <img src="\" style="\"height:78px" /></a></p>
и здесь updateText.php:
<?php
$filename = $_POST['name'];
$str = $_POST['editor1'];
$fh = fopen($filename, "w");
fwrite($fh, $str);
fclose($fh);
header("Location: modify.php");
?>
Поэтому я понятия не имею, что я испортил...
Похоже, магические цитаты испортили ваши $ _POST vars.
Отключите его в файле php.ini:
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
if (get_magic_quotes_gpc()) { function stripslashes_gpc(&$value) { $value = stripslashes($value); } array_walk_recursive($_GET, 'stripslashes_gpc'); array_walk_recursive($_POST, 'stripslashes_gpc'); array_walk_recursive($_COOKIE, 'stripslashes_gpc'); array_walk_recursive($_REQUEST, 'stripslashes_gpc'); }
Если вы хотите добавить HTML-код в CKEditor, вы должны сначала убедиться, что нажали кнопку "Источник", иначе в противном случае он будет кодировать входы, и вы получите проблему выше.