开发者社区> 问答> 正文

UEeditor如何保存HTML代码?报错

百度编辑器如何保存HTML到数据库?需要在前台提交到后台的时候将所有的HTML代码转义,之后从数据库取出来的时候在进行转义还原成HTML代码吗?

为什么我的一直从后台回显到前台的时候报错,主要是说我的内容有回车行、&不认识之类的。

展开
收起
爱吃鱼的程序员 2020-06-12 14:52:45 609 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    把HTML内容存到一个.html文件,再被这个文件路径存到数据库

    1、页面上的存到一个html文件中

    $cttDetailHtml=$_POST["cttDetailHtml"];

              $cttDetailHtml=str_replace("<head>",
                 "<head><metahttp-equiv='Content-Type'content='text/html;charset=utf-8'/> ",$cttDetailHtml);
              $htmlFile=fopen("templete/".$cid.".html","w");
              fwrite($htmlFile,$cttDetailHtml);
              fclose($htmlFile);

              $saveParam["TPL_PATH"]="templete/".$cid.".html";


    2、从HTML文件里读出来

    $htmlFile="";
            if($ctt["tplPath"]!=null){
              $fileName="templete/".$cid.".html";
              if(file_exists($fileName)){
                $htmlFile=file_get_contents($fileName);
                $htmlFile=str_replace('"',"'",$htmlFile);
                $htmlFile=preg_replace("/.<body.?>(.?)</body>./s","$1",$htmlFile);
              }
            }
             
            $data["htmlFile"]=$htmlFile;
    3、用jquery放到页面上

      <?phpif($htmlFile!=""){?>
      varcontent="<?phpecho$htmlFile;?>";
      ue.addListener("ready",function(){
        ue.setContent(content);
      });
      <?php}?>

    2020-06-12 14:53:02
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
《零基础HTML入门教程》 立即下载
天猫 HTML5 互动技术实践 立即下载
天猫HTML5互动技术实践 立即下载