【求助】ueditor1.4.3,php版本,回显调试失败。请教如何回显?

hgwyl 2020-10-20 12:50:34
<textarea id="editor" name="basic_content"><?php echo $basic_content; ?></textarea>
<script type="text/javascript">
UE.getEditor('editor');
</script>


编辑器是可以正常加载的。
现在需要做个回显——比如添加失败或编辑。

textarea 中,直接使用<?php echo $basic_content; ?>回显失败。
csdn和baidu了一大圈,没有找到可用的方法。

请各位指点!
...全文
135 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
下雨的声音丶 2020-10-20
  • 打赏
  • 举报
回复
那你看看console 里面有没有报错
hgwyl 2020-10-20
  • 打赏
  • 举报
回复
我修改了一下代码,在head区域,添加了setContent方法。 var content="一个php变量"; 如果直接使用文字的话,是可以正常使用的。(ueditor编辑框里有这段字) 具体代码如下
<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值
hgwyl 2020-10-20
  • 打赏
  • 举报
回复
引用 1 楼 下雨的声音丶 的回复:
你这个变量的值输出来了么,你打开调试模式找到这个textarea标签看看有内容不
如果我把ueditor的相关内容去掉,页面可以正常显示。 比如下面这样
<textarea name="basic_content"><?php echo $basic_content; ?></textarea>
一旦加上ueditor的相关内容就gg了,比如下面这样
<textarea id="editor" name="basic_content"><?php echo $basic_content; ?></textarea>
hgwyl 2020-10-20
  • 打赏
  • 举报
回复
引用 1 楼 下雨的声音丶的回复:
你这个变量的值输出来了么,你打开调试模式找到这个textarea标签看看有内容不
我检查一下试试
下雨的声音丶 2020-10-20
  • 打赏
  • 举报
回复
你这个变量的值输出来了么,你打开调试模式找到这个textarea标签看看有内容不
hgwyl 2020-10-20
  • 打赏
  • 举报
回复
问题找到和解决了。 问题:接受变量时,我用了个自定义函数
<?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>
再次谢过两位大哥!
引用 5 楼 下雨的声音丶 的回复:
那你看看console 里面有没有报错
引用 6 楼 迪奥乔斯达 的回复:
配置文件PHP下面有个config.json文件
hgwyl 2020-10-20
  • 打赏
  • 举报
回复
引用 6 楼 迪奥乔斯达 的回复:
配置文件PHP下面有个config.json文件
这个文件我之前也翻过,刚才又翻了一次。 有点靠近的有2个设置
focus:false,
autoClearinitialContent:false,
我都加上了,但是没有啥子效果
hgwyl 2020-10-20
  • 打赏
  • 举报
回复
引用 5 楼 下雨的声音丶 的回复:
那你看看console 里面有没有报错
正常的,没见有报错,就是获取不到php变量值
  • 打赏
  • 举报
回复
配置文件PHP下面有个config.json文件

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧