21,887
社区成员
发帖
与我相关
我的任务
分享
<textarea id="editor" name="basic_content"><?php echo $basic_content; ?></textarea>
<script type="text/javascript">
UE.getEditor('editor');
</script>
<script type="text/javascript">
function check_all(obj,cName)
{
var checkboxs = document.getElementsByName(cName);
for(var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}
}
var ue = UE.getEditor('editor', {
zIndex : 6 ,
//初始化编辑器宽度
initialFrameWidth:'99.5%',
//初始化编辑器高度
initialFrameHeight:'240',
//定义工具栏
toolbars: [
['source', '|','undo','redo','|','paragraph','forecolor','bold','underline','strikethrough','superscript','subscript','|']
,['justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','|','simpleupload', 'insertimage','attachment','|', 'spechars','map','|']
],
//高度自增长
autoHeightEnabled: true,
//固定toolbar的位置
autoFloatEnabled: true,
//关闭字数统计
wordCount:false,
//启用自动保存
enableAutoSave: true,
//自动保存间隔时间, 单位ms
saveInterval: 60000,
//关闭元素路径
elementPathEnabled:false,
//关闭右键菜单
enableContextMenu: false
});
var content="一个php变量";
//判断ueditor 编辑器是否创建成功
ue.addListener("ready", function () {
// editor准备好之后才可以使用
ue.setContent(content);
});
</script>
但是如果我将
var content="一个php变量";
改成
var content="<?php echo $basic_content; ?>";
却没用,editor编辑框内获取不到php定义的$basic_content值<textarea name="basic_content"><?php echo $basic_content; ?></textarea>
一旦加上ueditor的相关内容就gg了,比如下面这样
<textarea id="editor" name="basic_content"><?php echo $basic_content; ?></textarea>
<?php
function prep_variable_ueditor($variable_str) {
$variable_str=trim($variable_str); //清除字符串两边的空格
$variable_str=preg_replace("/\t/","",$variable_str); //使用正则表达式替换跳格(移至下一列)
$variable_str=preg_replace("/\r\n/","",$variable_str);//使用正则表达式替换回车键
$variable_str=preg_replace("/\r/","",$variable_str);//使用正则表达式替换软空格
$variable_str=preg_replace("/\n/","",$variable_str);//使用正则表达式替换回车键
$variable_str=preg_replace("/ /","",$variable_str);
$variable_str=preg_replace("/ /","",$variable_str);//替换html中的空格
$variable_str=stripslashes($variable_str);//删除由 addslashes() 函数添加的反斜杠
$variable_str=htmlspecialchars($variable_str);//把预定义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体
return $variable_str; //返回字符串
}
?>
比如下面这个
$basic_content=prep_variable_ueditor($_GET["basic_content"]);
好像是因为ueditor编辑框是生成代码的,所以在接受变量过程中,自定义函数把变量值给搞没了。
(技术菜鸟,不敢肯定)
解决方式是将其中4行注释掉
<?php
function prep_variable_ueditor($variable_str) {
$variable_str=trim($variable_str); //清除字符串两边的空格
$variable_str=preg_replace("/\t/","",$variable_str); //使用正则表达式替换跳格(移至下一列)
//$variable_str=preg_replace("/\r\n/","",$variable_str);//使用正则表达式替换回车键
$variable_str=preg_replace("/\r/","",$variable_str);//使用正则表达式替换软空格
$variable_str=preg_replace("/\n/","",$variable_str);//使用正则表达式替换回车键
//$variable_str=preg_replace("/ /","",$variable_str);
//$variable_str=preg_replace("/ /","",$variable_str);//替换html中的空格
$variable_str=stripslashes($variable_str);//删除由 addslashes() 函数添加的反斜杠
//$variable_str=htmlspecialchars($variable_str);//把预定义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体
return $variable_str; //返回字符串
}
?>
测试结果:ueditor编辑框
1、可以正常使用
2、单行字之间可以保留空格
3、可以正常换行
至于引用editor的页面,直接使用代码就可以了
<textarea id="editor" name="basic_content"><?php echo $basic_content; ?></textarea>
<script type="text/javascript">
UE.getEditor('editor'); //名字必须与上面一致
</script>
再次谢过两位大哥!
focus:false,
autoClearinitialContent:false,
我都加上了,但是没有啥子效果