有一个(在服务器上)本地存储的HTML文件,我需要向用户展示,并允许使用对它进行修改和保存。(类似于wordpress的模板文件编辑器)。
我使用的是ACE编辑器。
我的javascript代码。
$(document).ready(function() {
var editor = ace.edit("editor");
editor.getSession().setMode("ace/mode/html");
editor.setTheme("ace/theme/chrome");
editor.setValue("<?php echo addslashes(file_get_contents("abc.html")); ?>");
editor.gotoLine(1);
});
文件abc.html中的代码
我的问题:虽然我已经使用了加号,但还是有一些字符导致了问题,难道没有一种方法可以直接提供文件给ACE编辑器吗?
有没有其他这样的编辑器可以直接提供文件名来打开?
EDIT: SOLVED!
我没有通过setValue()函数传递文件文本,而是直接在PRE标签中打印文本
<pre id="editor"><?php echo htmlentities(file_get_contents($input_dir."abc.html")); ?></pre>
它的工作。
正确的转义是
htmlspecialchars(addslashes(file_get_contents("abc.html")));
editor.setValue("<?php echo addslashes(file_get_contents("abc.html")); ?>");
abc.html脱离了php代码,语法错误。
editor.setValue('<?php echo addslashes(file_get_contents("abc.html")); ?>');
这可能是工作。