有一个(在服务器上)本地存储的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编辑器提供文件的方法吗?
有没有其他这样的编辑器,可以直接提供一个文件名来打开?
编辑:已解决!
我没有通过setValue()函数传递文件文本,而是直接在前标记中打印文本
<pre id="editor"><?php echo htmlentities(file_get_contents($input_dir."abc.html")); ?></pre>啊,真灵。
发布于 2013-03-03 22:17:37
正确的转义是
htmlspecialchars(addslashes(file_get_contents("abc.html")));发布于 2013-08-10 20:29:15
editor.setValue("<?php echo addslashes(file_get_contents("abc.html")); ?>");是错误的。abc.html不在php代码中。语法错误
editor.setValue('<?php echo addslashes(file_get_contents("abc.html")); ?>');这可能行得通。尚未测试
https://stackoverflow.com/questions/15186558
复制相似问题